我使用以下代码向我展示了listview中文本的位置。如果我在textedit中写下位置数,我想显示文本或字符串。
简而言之......如果我从列表视图中写出项目的位置编号,它会给出我在该特定位置的文本或字符串的结果。
public void onClick(View v){
try {
View parentRow = (View) v.getParent();
list = (ListView) parentRow.getParent();
final int position = lista.getPositionForView(parentRow);
Toast.makeText(getBaseContext(),"The "+position, Toast.LENGTH_SHORT).show();
} catch (Exception e) {
e.printStackTrace();
}
}
答案 0 :(得分:0)
所以它就像这样(伪):
final EditText edittext = (EditText) findViewById(...);
Button button = (Button) findViewById(...);
final ListView listview = (ListView) findViewById(...);
listview.setAdapter(...) // remember to set an adapter to listview
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int position = Integer.parseInt(edittext.getText().toString()); // make sure to have an numeric edittext
Object obj = listview.getAdapter().getItem(position); // this is your object, string, text (whatever)
}
});