Android listview-Element klicken funktioniert nicht
Ich habe ähnliche Fragen und versucht die Lösungen wie die Einstellung justierbares zu falsch, aber es ist immer noch nicht funktioniert. Hier ist mein layout, enthält die listview:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView
android:id="@+id/listView_open_groups"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/button_add_group"
android:layout_alignParentTop="true"
></ListView>
<Button
android:id="@+id/button_add_group"
android:text="Add Group"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:focusable="false"
/>
<Button
android:id="@+id/button_add_entry"
android:text="Add Entry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toRightOf="@+id/button_add_group"
android:focusable="false"
/>
</RelativeLayout>
Und meine custom_list_row
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:longClickable="true" >
<ImageView
android:id="@+id/imgView_group_entry_icon"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:focusable="false"
/>
<TextView
android:id="@+id/textView_group_entry_name"
android:layout_toRightOf="@id/imgView_group_entry_icon"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="false"/>
<TextView
android:id="@+id/textView_group_entry_type"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"/>
</RelativeLayout>
Und meine benutzerdefinierte adapter:
public class OpenDbListAdapter extends ArrayAdapter<KeepassDBGroupv1>{
Context context;
public OpenDbListAdapter(Context context, int resource,
List<KeepassDBGroupv1> objects) {
super(context, resource, objects);
this.context=context;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
KeepassDBGroupv1 rowItem = getItem(position);
LayoutInflater mInflater = (LayoutInflater) context
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = mInflater.inflate(R.layout.custom_list_row, null);
holder = new ViewHolder();
holder.name = (TextView) convertView.findViewById(R.id.textView_group_entry_name);
holder.imageView = (ImageView) convertView.findViewById(R.id.imgView_group_entry_icon);
holder.type = (TextView) convertView.findViewById(R.id.textView_group_entry_type);
convertView.setTag(holder);
} else
holder = (ViewHolder) convertView.getTag();
holder.name.setText(rowItem.getGroupName());
holder.type.setText("Group");
Drawable d = context.getResources().getDrawable(context.getResources().getIdentifier("ic"+Integer.toString(rowItem.getImageId()), "drawable", context.getPackageName()));
holder.imageView.setImageDrawable(d);
//App.getDB().drawFactory.assignDrawableTo(holder.imageView, context.getResources(), rowItem.icon);
return convertView;
}
private class ViewHolder {
ImageView imageView;
TextView name;
TextView type;
}
}
Und schließlich, hier ist, wie ich die listener:
public class OpenDbActivity extends Activity{
static ListView lv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_opendb);
db = MyApplication.keepassdb;
InitializeComponents();
}
private void InitializeComponents() {
lv = (ListView) findViewById(R.id.listView_open_groups);
OpenDbListAdapter adapter = new OpenDbListAdapter(this, R.layout.custom_list_row, childGroups);
lv.setAdapter(adapter);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Log.d("Something");
}
});
}
Kann jeder sehen, was das problem ist?
Dank
- versuchen Sie dies zu Ihrem
Relative Layout
android:descendantFocusability="blocksDescendants"
in Ihremcustom_list_row.xml
- Dank ich habe versucht, es in meinem relativelayout, das enthält meine listview-tag, aber noch nicht wotking
- ich denke, ich habe versucht, Sie in die falsche layout-Datei wird versuchen Sie es erneut
- nope, funktioniert immer noch nicht
- und versuchen, Sie zu entfernen
android:focusable="false"
aus allen das Kind IhrerRelative Layout
- danke, aber es funktioniert immer noch nicht. Ich denke, ich werde versuchen, den Hörerinnen der adapter
InformationsquelleAutor yrazlik | 2014-05-12
Schreibe einen Kommentar Antworten abbrechen
Du musst angemeldet sein, um einen Kommentar abzugeben.
Ich auch konfrontiert mit diesem Problem, ich krank von diesem Problem durch die Einstellung auf Zuhörer
convertView
voncustom adapter
. Ich weiß nicht, ist es ein guter Ansatz, aber es löste mein Problem.Aber das problem ist aus der
custom_list_row.xml
, wenn Sie klicken Sie auf die Listenansicht Artikel,und diese tags sind nicht verantwortlich für die Entlassung der
ItemClickListener
.Verändern Sie den Wert der Eigenschaft
android:layout_width
von tags in dercustom_list_row.xml
zu"wrap_content"
oder entfernen Sie die tags und versuchen Sie es erneut.nach Einstellung
für Ihre ListView-Inhalt in Ihre ListView-Tag Hinzufügen