下面是我的代码,它适用于水平显示列表视图.如何将其更改为grIDvew.我应该做些什么更改才能将其更改为grIDvIEw?请帮帮我
public class fifthscreen extends Activity {int IOConnect = 0;String _response;String status;horizontallistVIEw ListvIEw;categorylistadapter3 cla;String URL, URL2;String SelectMenuAPI;static ArrayList<Long> category_ID = new ArrayList<Long>();static ArrayList<String> category_name = new ArrayList<String>();static ArrayList<String> category_image = new ArrayList<String>();public static String allergen2;String name;String url1;@OverrIDepublic voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.fifthscreen); ListvIEw = (horizontallistVIEw) this.findVIEwByID(R.ID.ListvIEw2); cla = new categorylistadapter3(fifthscreen.this); new TheTask().execute();}public class TheTask extends AsyncTask<VoID, String, String> { @OverrIDe protected voID onPreExecute() { super.onPreExecute(); } @OverrIDe protected String doInBackground(VoID... arg0) { try { httpGet request = new httpGet(url); httpResponse response = clIEnt.execute(request); httpentity resEntity = response.getEntity(); _response = EntityUtils.toString(resEntity); } catch (Exception e) { e.printstacktrace(); } return _response; } @OverrIDe protected voID onPostExecute(String result) { super.onPostExecute(result); try { JsONObject Json2 = new JsONObject(result); status = Json2.getString("status"); if (status.equals("1")) { JsONArray school4 = Json2.getJsONArray("dish_allergen"); // for (int i = 0; i < school4.length(); i++) { JsONObject object = school4.getJsONObject(i); category_ID.add((long) i); category_name.add(object.getString("name")); category_image.add(object.getString("image")); } } else { JsONArray school2 = Json2.getJsONArray("data"); for (int i = 0; i < school2.length(); i++) { JsONObject object = school2.getJsONObject(i); category_ID.add((long) i); category_name.add(object.getString("name")); } } } catch (JsONException e) { // Todo auto-generated catch block e.printstacktrace(); } ListvIEw.setAdapter(cla); }} } public class categorylistadapter3 extends BaseAdapter {private Activity activity;private Aquery androIDAquery;public categorylistadapter3(Activity act) { this.activity = act;// imageLoader = new ImageLoader(act);}public int getCount() { // Todo auto-generated method stub return fifthscreen.category_ID.size();}public Object getItem(int position) { // Todo auto-generated method stub return position;}public long getItemID(int position) { // Todo auto-generated method stub return position;}public VIEw getVIEw(int position, VIEw convertVIEw, VIEwGroup parent) { // Todo auto-generated method stub VIEwHolder holder; androIDAquery = new Aquery(getcontext()); if(convertVIEw == null){ LayoutInflater inflater = (LayoutInflater) activity .getSystemService(Context.LAYOUT_INFLATER_SERVICE); convertVIEw = inflater.inflate(R.layout.vIEwitem2, null); holder = new VIEwHolder(); convertVIEw.setTag(holder); }else{ holder = (VIEwHolder) convertVIEw.getTag(); } holder.txtText = (TextVIEw) convertVIEw.findVIEwByID(R.ID.Title2); holder.imgThumb = (ImageVIEw) convertVIEw.findVIEwByID(R.ID.image2); holder.txtText.setText(fifthscreen.category_name.get(position)); // imageLoader.displayImage(fifthscreen.category_image.get(position), activity, holder.imgThumb); androIDAquery.ID(holder.imgThumb).image(fifthscreen.category_image.get(position), false, false); return convertVIEw;}private Activity getcontext() { // Todo auto-generated method stub return null;}static class VIEwHolder { TextVIEw txtText; ImageVIEw imgThumb;} } <!--- fifithscreen.xml---> <linearLayout androID:layout_wIDth="fill_parent" androID:layout_height="fill_parent" androID:layout_marginleft="10dp" androID:layout_marginRight="10dp" androID:layout_below="@+ID/test_button_text5" androID:orIEntation="vertical" > <com.example.examplecode.horizontallistVIEw androID:ID="@+ID/ListvIEw2" androID:layout_wIDth="wrap_content" androID:layout_height="120dp" androID:layout_below="@+ID/test_button_text5" androID:background="#ffffff"/> </linearLayout> <!--vIEwitem2.xml---> <?xml version="1.0" enCoding="utf-8"?> <linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:orIEntation="vertical" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" > <ImageVIEwandroID:ID="@+ID/image2" androID:layout_wIDth="90dp" androID:layout_height="70dp" androID:scaleType="fitXY" androID:padding="5dp" androID:layout_marginleft="5dp" androID:layout_marginRight="5dp"androID:src="@drawable/ic_launcher"/><TextVIEwandroID:ID="@+ID/Title2"androID:layout_wIDth="90dp"androID:layout_height="wrap_content"androID:textcolor="#000"androID:paddingtop="10dp"androID:gravity="center_horizontal"/> </linearLayout>
解决方法:
完全没有变化.只需将GrIDVIEw的适配器设置为ListVIEw的设置即可.
总结以上是内存溢出为你收集整理的android – 如何将listview转换为gridview全部内容,希望文章能够帮你解决android – 如何将listview转换为gridview所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)