我有一个使用自定义适配器的ListVIEw,但我不能单击ListVIEw项..
列表视图的活动..
package com.adhamenaya.projects;import java.util.ArrayList;import androID.app.Activity;import androID.content.Context;import androID.os.AsyncTask;import androID.os.Bundle;import androID.vIEw.LayoutInflater;import androID.vIEw.VIEw;import androID.vIEw.VIEw.OnClickListener;import androID.vIEw.VIEwGroup;import androID.Widget.BaseAdapter;import androID.Widget.button;import androID.Widget.Filter;import androID.Widget.Filterable;import androID.Widget.ListVIEw;import androID.Widget.TextVIEw;import androID.Widget.Toast;import com.adhamenaya.classes.Place;public class PlacesListActivity extends Activity { private ArrayList<Place> places; private ArrayList<String> items; GrIDvIEwAdapter mAdapter; private ListVIEw lvPlaces; private EfficIEntAdapter adap; public voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.places_List); lvPlaces = (ListVIEw) this.findVIEwByID(R.ID.lvPlaces); new Dowanloadplaces().execute(""); } private voID bindList(ArrayList<Place> places) { this.places = places; // Start creating the List vIEw to show articles items = new ArrayList<String>(); for (int i = 0; i < places.size(); i++) { items.add(String.valueOf(places.get(i).mname)); } adap = new EfficIEntAdapter(this); adap.notifyDataSetChanged(); lvPlaces.setAdapter(adap); } // EfficIEntAdapter : to make a customized List vIEw item public class EfficIEntAdapter extends BaseAdapter implements Filterable { // The function of inflater to convert objects from XML layout file (i.e. main.xml) to a programmable LayoutInflater inflater; Context context; public EfficIEntAdapter(Context context) { inflater = LayoutInflater.from(context); this.context = context; } public int getCount() { // Get the number of items in the List return items.size(); } public Object getItem(int position) { // To return item from a List in the given position return items.get(position); } public long getItemID(int position) { // Todo auto-generated method stub return 0; } public VIEw getVIEw(final int position, VIEw convertVIEw,VIEwGroup parent) { VIEwHolder holder; if (convertVIEw == null) { convertVIEw = inflater.inflate(R.layout.adaptor_content, null); holder = new VIEwHolder();// Create an object to hold at components in the List vIEw item holder.textline = (TextVIEw) convertVIEw.findVIEwByID(R.ID.textline); holder.buttonline = (button) convertVIEw.findVIEwByID(R.ID.buttonline); holder.buttonline.setonClickListener(new OnClickListener() { private int pos = position; public voID onClick(VIEw v) { places.remove(pos); bindList(places);// to bind List items Toast.makeText(getApplicationContext(),"Deleted successfuly :)", Toast.LENGTH_LONG).show(); } }); convertVIEw.setTag(holder); } else { holder = (VIEwHolder) convertVIEw.getTag(); } // Bind the data efficIEntly with the holder. holder.textline.setText(String.valueOf(places.get(position).mname)); return convertVIEw; } public Filter getFilter() { // Todo auto-generated method stub return null; } } // VIEwHolder : class that represents a List vIEw items static class VIEwHolder { TextVIEw textline; button buttonline; } // DownloadRSSFeedsTask: works in a separate thread private class Dowanloadplaces extends AsyncTask<String, VoID, ArrayList<Place>> { @OverrIDe protected ArrayList<Place> doInBackground(String... params) { ArrayList<Place> places = new ArrayList<Place>(); Place p = new Place(); for(int i =0;i<25;i++){ p.mname = "Al Mathaf Hotel"; places.add(p); } return places; } @OverrIDe protected voID onPostExecute(ArrayList<Place> places) { bindList(places); } }}
places_List.xml布局
<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:orIEntation="vertical" androID:layout_wIDth="fill_parent" androID:layout_height="fill_parent"> <ListVIEw androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:ID="@+ID/lvPlaces"> </ListVIEw></linearLayout>
adaptor_content.xml布局
<ImageVIEw androID:ID="@+ID/imageVIEw1" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_alignleft="@+ID/textline" androID:layout_centerVertical="true" androID:src="@drawable/settings" /></relativeLayout>
解决方法:
试着这个来获得焦点:
VIEw.getFocus();
以上是内存溢出为你收集整理的android – ListView项目不可点击.为什么?全部内容,希望文章能够帮你解决android – ListView项目不可点击.为什么?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)