سلام دوستان ... من می خوام یه لیست ویو به حالت اسکرول بینهایت داشته باشم
کلاس اداپتور اینجوری تعریف کردم
کلاس اداپتور اینجوری تعریف کردم
package com.oneremind.oneremind; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.ImageView; import android.widget.TextView; import java.util.List; class PostAddapor extends BaseAdapter { String[] result; Context context; int[] imageId; private static LayoutInflater inflater = null; public PostAddapor(BaseActivity mainActivity) { // TODO Auto-generated constructor stub context = mainActivity; // imageId = prgmImages; inflater = (LayoutInflater) context. getSystemService(Context.LAYOUT_INFLATER_SERVICE); } public void setData(String[] title) { result = title; } @Override public int getCount() { // TODO Auto-generated method stub return result.length; } @Override public Object getItem(int position) { // TODO Auto-generated method stub return position; } @Override public long getItemId(int position) { // TODO Auto-generated method stub return position; } public class Holder { TextView tv; ImageView img; } @Override public View getView(final int position, View convertView, ViewGroup parent) { // TODO Auto-generated method stub Holder holder = new Holder(); View rowView = inflater.inflate(R.layout.post_listview, null); holder.tv = (TextView) rowView.findViewById(R.id.txttitle); holder.tv.setText(result[position]); return rowView; } }کد دریافت اطلاعات از سرور با loopj
public void getPost(int page) { RequestParams params=new RequestParams(); params.put("username",G.username); params.put("password", G.password); AsyncHttpClient client = new AsyncHttpClient(); client.post(G.baseUrl + "post/get_post?page=" + page, params, new AsyncHttpResponseHandler() { @Override public boolean getUseSynchronousMode() { return false; } @Override public void onStart() { loading.show(); // called before request is started } @Override public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) { Log.i("state", "state: " + statusCode); String res = new String(responseBody); try { JSONArray result = new JSONArray(res); // List<PostList> postLists=new ArrayList<PostList>(); // String[] title = new String[0]; String[] title = new String[result.length()]; for (int i = 0; i <= result.length() - 1; ++i) { title[i] += result.getJSONObject(i).getString("id"); } addaptor.setData(title); addaptor.notifyDataSetChanged(); listOfPost.setAdapter(addaptor); } catch (JSONException e) { e.printStackTrace(); } // arr= new JSONArray(new String(responseBody)); loading.hide(); } @Override public void onFailure(int statusCode, Header[] headers, byte[] errorResponse, Throwable e) { // called when response HTTP status is "4XX" (eg. 401, 403, 404) loading.hide(); Log.i("state", "state: " + statusCode); } @Override public void onRetry(int retryNo) { // called when request is retried loading.setTitle("on retry ..."); } }); }