中的自定義列表視圖中獲取所選項目我已經使用基礎適配器創建了自定義列表視圖。我想從列表視圖中獲取所選項目。我嘗試了不同的解決方案,但他們都沒有工作。我的ListView控件的代碼如下所示:無法從android
class SingleRow {
String mFetchedJobTitle;
String mFetchedCompanyName;
String mFetchedExperience;
String mFetchedLocation;
SingleRow(String mFetchedJobTitle, String mFetchedCompanyName, String mFetchedExperience, String mFetchedLocation) {
this.mFetchedJobTitle = mFetchedJobTitle;
this.mFetchedCompanyName = mFetchedCompanyName;
this.mFetchedExperience = mFetchedExperience;
this.mFetchedLocation = mFetchedLocation;
}
}
class MyAdapter extends BaseAdapter {
ArrayList<SingleRow> list;
Context context;
MyAdapter(Context c) {
context = c;
list = new ArrayList<SingleRow>();
String[] mFetchedJobTitle1 = searchJobTitle;
String[] mFetchedCompanyName1 = searchCompanyName;
String[] mFetchedExperience1 = searchExperience;
String[] mFetchedLocation1 = searchLocation;
for (int i = 0; i < mArrayLength; i++) {
list.add(new SingleRow(mFetchedJobTitle1[i], mFetchedCompanyName1[i], mFetchedExperience1[i], mFetchedLocation1[i]));
}
}
@Override
public int getCount() {
return list.size();
}
@Override
public Object getItem(int position) {
return list.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View row = inflater.inflate(R.layout.custom_search_row, parent, false);
TextView title = (TextView) row.findViewById(R.id.textViewJobTitle);
TextView companyName = (TextView) row.findViewById(R.id.textViewCompanyName);
TextView experience = (TextView) row.findViewById(R.id.textViewExperience);
TextView location = (TextView) row.findViewById(R.id.textViewLocation);
SingleRow temp = list.get(position);
title.setText(temp.mFetchedJobTitle);
companyName.setText(temp.mFetchedCompanyName);
experience.setText(temp.mFetchedExperience);
location.setText(temp.mFetchedLocation);
return row;
}
}
的ListView OnItemClickListener代碼:
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
mSelectedItem = mListView.getItemAtPosition(i).toString();
String mselected = (String) adapterView.getSelectedItem();
Log.d("selecteditem", ""+mselected);
Log.d("selecteditem", ""+mSelectedItem);
}
});
}
}
我得到mSelectedItem的價值:
[email protected]
如何得到確切的字符串值。任何人都可以給我一個想法。所有建議都歡迎。
什麼是mSelectedItem類型' – Tauqir