使用onItemClickListener
请参阅我的代码:
ref = new Firebase("https://.......firebaseio.com/Service");
final FirebaseListAdapter<MainCategory> adapter = new FirebaseListAdapter<MainCategory>(getActivity(), MainCategory.class,
android.R.layout.simple_list_item_1,
ref) {
@Override
protected void populateView(View view, MainCategory s, int i) {
TextView tv = (TextView) view.findViewById(android.R.id.text1);
tv.setText(s.getTitle());
}
};
listView.setAdapter(adapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String itemId = String.valueOf(parent.getId());
String root = String.valueOf(ref.getRoot().getKey());
MainCategory object = (MainCategory) parent.getItemAtPosition(position);
Toast.makeText(getContext(), itemId+"____"+"__"+root, Toast.LENGTH_SHORT).show();
}
});
答案 0 :(得分:1)
您正在寻找:
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String key = adapter.getRef(position).getKey()
}