-2
スワイプビューでonRefresh
を使用してリストビューを更新するにはどうすればよいですか?ここに私のコードありがとうございます。私は仕事をすることはできません。Androidのプルダウンをリフレッシュする方法:更新方法
public class rentList extends Fragment implements AsyncResponse, AdapterView.OnItemClickListener, SwipeRefreshLayout.OnRefreshListener {
final String TAG = this.getClass().getName();
private ArrayList<Cars> carList;
private ListView lvCars;
private FunDapter<Cars> adapter;
SharedPreferences pref;
SharedPreferences.Editor editor;
SwipeRefreshLayout swipeCar;
public rentList() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View v = inflater.inflate(R.layout.fragment_rent_list, container, false);
ImageLoader.getInstance().init(UILConfig.config(getActivity()));
PostResponseAsyncTask taskRead = new PostResponseAsyncTask(getActivity(), this);
taskRead.execute("http://carkila.esy.es/product.php");
lvCars = (ListView) v.findViewById(R.id.lvCars);
registerForContextMenu(lvCars);
pref = getActivity().getSharedPreferences("Login.conf", Context.MODE_PRIVATE);
Log.d(TAG, pref.getString("username",""));
Log.d(TAG, pref.getString("password",""));
swipeCar = (SwipeRefreshLayout) v.findViewById(R.id.swipeCar);
swipeCar.setOnRefreshListener(this);
return v;
}
@Override
public void processFinish(String s) {
carList = new JsonConverter<Cars>().toArrayList(s, Cars.class);
BindDictionary<Cars> dict = new BindDictionary<Cars>();
dict.addDynamicImageField(R.id.ivImg, new StringExtractor<Cars>() {
@Override
public String getStringValue(Cars product, int position) {
return product.Image;
}
}, new DynamicImageLoader() {
@Override
public void loadImage(String url, ImageView imageView) {
ImageLoader.getInstance().displayImage(url, imageView); // Default options will be used
}
});
dict.addStringField(R.id.tvCarModel, new StringExtractor<Cars>() {
@Override
public String getStringValue(Cars product, int position) {
return "Car Model: " + product.Car_Model;
}
});
dict.addStringField(R.id.tvCarType, new StringExtractor<Cars>() {
@Override
public String getStringValue(Cars product, int position) {
return "Car Type: " + product.Car_Type;
}
});
dict.addStringField(R.id.tvCapacity, new StringExtractor<Cars>() {
@Override
public String getStringValue(Cars product, int position) {
return "Capacity: " + product.Capacity;
}
});
dict.addStringField(R.id.tvFuelType, new StringExtractor<Cars>() {
@Override
public String getStringValue(Cars product, int position) {
return "Fuel Type: " + product.FuelType;
}
});
dict.addStringField(R.id.tvPlateNumber, new StringExtractor<Cars>() {
@Override
public String getStringValue(Cars product, int position) {
return "Plate Number: " + product.PlateNumber;
}
});
dict.addStringField(R.id.tvPoster, new StringExtractor<Cars>() {
@Override
public String getStringValue(Cars product, int position) {
return "Posted by: " + product.owner;
}
});
dict.addStringField(R.id.tvPrice, new StringExtractor<Cars>() {
@Override
public String getStringValue(Cars product, int position) {
return "Price: " + product.carPrice;
}
});
adapter = new FunDapter<>(
getActivity(), carList, R.layout.layout_list, dict);
if(swipeCar.isRefreshing()){
swipeCar.setRefreshing(false);
}
lvCars.setAdapter(adapter);
lvCars.setOnItemClickListener(this);
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Cars selectedCars = carList.get(position);
Intent in = new Intent(getActivity(), DetailActivity.class);
in.putExtra("cars", selectedCars);
startActivity(in);
}
@Override
public void onRefresh() {
Toast.makeText(getActivity(), "refreshhh!!!", Toast.LENGTH_SHORT).show();
}
}
の.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.example.kun.carkila.ListActivity"
tools:showIn="@layout/activity_list">
<android.support.v4.widget.SwipeRefreshLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/swipeCar">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/lvCars"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:outlineProvider="none"/>
</android.support.v4.widget.SwipeRefreshLayout>
</RelativeLayout>
質問はまだ明らかではありません。あなたは何を達成しようとしているのか、何を得ているのか説明してください。 – dex
@dex - 私の 'swiperefreshlayout'を動作させることはできません。 :c –
あなたがリフレッシュするために引っ張ると、何らかの種類の円が得られましたか? onRefreshメソッドにトーストメッセージがありますか? – dex