我有setOnItemClickListener
代碼:如何從自定義列表視圖適配器中獲取數據並傳遞給intent放置額外?
userListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String user_name = String.valueOf(parent.getItemAtPosition(position));
Log.i("data_items",user_name);
Toast.makeText(MainActivity.this,user_name,Toast.LENGTH_SHORT).show();
}
});
日誌給我:
[email protected]
每一行點擊讓我在最後一個異數。例如
[email protected]
它是我的SQLite的數據庫?如何閱讀我的自定義列表適配器的onClickItemListene?
任何人都可以幫助我嗎?
爲ArrayAdapater
private class UserListAdapter extends ArrayAdapter<UserList> {
private ArrayList<UserList> items;
public UserListAdapter(@NonNull Context context, @LayoutRes int textViewResourceId, @NonNull ArrayList<UserList> objects) {
super(context, textViewResourceId, objects);
this.items = objects;
}
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
View v = convertView;
if(v == null)
{
LayoutInflater layoutInflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = layoutInflater.inflate(R.layout.user_list_item,null);
}
UserList userList = items.get(position);
if(userList != null)
{
TextView usernameTextView = (TextView) v.findViewById(R.id.usernameTextView);
TextView fullnameTextViewFeatured = (TextView) v.findViewById(R.id.fullnameTextViewFeatured);
if(usernameTextView != null)
{
usernameTextView.setText(userList.getUser_name());
}
if(fullnameTextViewFeatured != null)
{
fullnameTextViewFeatured.setText(userList.getFull_name());
}
}
return v;
}
}
將適配器的代碼,請 –
ArrayAdapter @Blackbelt – Nere