-1
リストビューで10個のレコードをフェッチし、下からスクロールで他のレコードをフェッチしたい。私はこの新しいことで私を助けてください。フラグメントリストビューの下にscollのjsonデータをフェッチする方法
Latest_Fragment.java
private static final String TAG = LatestFragment.class.getSimpleName();
// Movies json url
private static final String url = "http://abc.news/android/lastest.php?page=1";
private ProgressDialog pDialog;
private List<Movie> movieList = new ArrayList<Movie>();
private List<Movie> additems;
private ListView listView;
private CustomListAdapter adapter;
boolean flag_loading = true;
private static String Title="title";
private static String Genre="genre";
private static String Rating="rating";
private static String Sec_id="secid";
private static String Category="category";
private static String bitmap="thumbnailUrl";
ListView list;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.latest_layout, container, false);
//getActivity().getActionBar().setDisplayHomeAsUpEnabled(true);
Intent intent2 = new Intent();
getActivity().setResult(Activity.RESULT_OK, intent2);
list = (ListView) v.findViewById(R.id.list);
adapter = new CustomListAdapter(getActivity(), movieList);
list.setAdapter(adapter);
pDialog = new ProgressDialog(getActivity());
// Showing progress dialog before making http request
pDialog.setMessage("Loading...");
pDialog.show();
// Creating volley request obj
JsonArrayRequest movieReq = new JsonArrayRequest(url,
new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
Log.d(TAG, response.toString());
hidePDialog();
// flag_loading = false;
// Parsing json
for (int i = 0; i < response.length(); i++) {
try {
JSONObject obj = response.getJSONObject(i);
Movie movie = new Movie();
movie.setSec_id(obj.getString("sec_id"));
movie.setCategory(obj.getString("category"));
movie.setTitle(obj.getString("title"));
movie.setThumbnailUrl(obj.getString("image"));
movie.setRating(obj.getString("rating"));
// movie.setYear(obj.getString("releaseYear"));
movie.setGenre(obj.getString("genre"));
// Genre is json array
// adding movie to movies array
movieList.add(movie);
} catch (JSONException e) {
e.printStackTrace();
}
}
// notifying list adapter about data changes
// so that it renders the list view with updated data
adapter.notifyDataSetChanged();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
if (error instanceof NoConnectionError){
Toast.makeText(getActivity().getBaseContext(), "Bummer..There's No Internet connection!", Toast.LENGTH_LONG).show();
}
}
});
// Adding request to request queue
AppController.getInstance().addToRequestQueue(movieReq);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Intent intent = new Intent(getActivity(), News_Detail.class);
bitmap = ((Movie)movieList.get(position)).getThumbnailUrl();
intent.putExtra("images", bitmap);
final String names = ((TextView) view.findViewById(R.id.title)).getText().toString();
intent.putExtra(Title, names);
String genredescription = ((TextView) view.findViewById(R.id.genre)).getText().toString(); //must for send data
intent.putExtra(Genre, genredescription);
String date = ((TextView) view.findViewById(R.id.rating)).getText().toString();
intent.putExtra(Rating, date);
startActivity(intent);
}
});
return v;
}
@Override
public void onDestroy() {
super.onDestroy();
hidePDialog();
}
private void hidePDialog() {
if (pDialog != null) {
pDialog.dismiss();
pDialog = null;
}
}
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getActivity().getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
}
customlistadapter.java
private Activity activity;
private LayoutInflater inflater;
private List<Movie> movieItems;
ImageLoader imageLoader = AppController.getInstance().getImageLoader();
public CustomListAdapter(Activity activity, List<Movie> movieItems) {
this.activity = activity;
this.movieItems = movieItems;
}
@Override
public int getCount() {
return movieItems.size();
}
@Override
public Object getItem(int location) {
return movieItems.get(location);
}
@Override
public long getItemId(int position) {
return position;
}
// first row layout change below code is working
@Override
public int getViewTypeCount() { return 2; }
//if remove below code then chage layout randomly
@Override
public int getItemViewType(int position) {
if (position == 0) {
return 0;
} else {
return 1;
}
}
// first row layout change above code is working
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (inflater == null)
inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null)
if(position == 0) {
convertView = inflater.inflate(R.layout.list_row2, null);
}else
{
convertView = inflater.inflate(R.layout.list_row, null);
}
if (imageLoader == null)
imageLoader = AppController.getInstance().getImageLoader();
NetworkImageView thumbNail = (NetworkImageView) convertView.findViewById(R.id.thumbnail);
final TextView sec_id = (TextView) convertView.findViewById(R.id.sec_id);
final TextView category = (TextView) convertView.findViewById(R.id.category);
TextView title = (TextView) convertView.findViewById(R.id.title);
TextView rating = (TextView) convertView.findViewById(R.id.rating);
TextView genre = (TextView) convertView.findViewById(R.id.genre);
//TextView year = (TextView) convertView.findViewById(R.id.releaseYear);
// getting movie data for the row
Movie m = movieItems.get(position);
// thumbnail image
thumbNail.setImageUrl(m.getThumbnailUrl(), imageLoader);
// title
title.setText(m.getTitle());
// rating
rating.setText(m.getRating());
// genre
genre.setText(m.getGenre());
sec_id.setText(m.getSec_id());
category.setText(m.getCategory());
// release year
// year.setText(m.getYear());
ImageView btn = (ImageView) convertView.findViewById(R.id.share);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(android.content.Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, "\n" + "\n" + "http://vasundharadeep.news/News/"+sec_id.getText().toString()+"/"+category.getText().toString());
activity.startActivity(intent);
}
});
return convertView;
}
}
コードはあなたに私はplsはトリングてるOK離れて行くいけない –
:)アンドロイドで新たなんだ、私のリストビューでこれを使うリストでRecyclerViewを交換する方法を教えてください:) –
を支援する場合は受け入れるとupvote、私は –