gpt4 book ai didi

android - Listview Onitemclick 没有任何反应

转载 作者:行者123 更新时间:2023-11-29 20:47:29 26 4
gpt4 key购买 nike

这是我的代码

public class VorherbestimmungenActivity extends Activity {
private ListView lv1;
ArrayAdapter<String> adapter;
EditText inputSearch;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ThemeUtils.onActivityCreateSetTheme(this);
setContentView(R.layout.vorherbestimmung);

String products[] = getResources().getStringArray(R.array.vorherbestimmung);
lv1 = (ListView) findViewById(R.id.listView1);
inputSearch = (EditText) findViewById(R.id.inputSearch);
adapter = new ArrayAdapter < String > (this, R.layout.list_item, R.id.product_name, products);

lv1.setAdapter(adapter);
inputSearch.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
// When user changed the Text
VorherbestimmungenActivity.this.adapter.getFilter().filter(cs);
}

@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
// TODO Auto-generated method stub
}

@Override
public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub


lv1.setOnItemClickListener(new OnItemClickListener() { @Override
public void onItemClick(AdapterView<?> arg0, View view,
int position, long arg3) {

if (position == 0) {
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("text/plain");
String shareMessage = "This is Item1";
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT,shareMessage);
startActivity(Intent.createChooser(shareIntent, "Entscheiden Sie �ber was Sie teilen m�chten:"));
} else if (position == 1) {
Intent shareIntent1 = new Intent(android.content.Intent.ACTION_SEND);
shareIntent1.setType("text/plain");
String shareMessage1 = "This is Item2";
shareIntent1.putExtra(android.content.Intent.EXTRA_TEXT,shareMessage1);
startActivity(Intent.createChooser(shareIntent1, "Entscheiden Sie �ber was Sie teilen m�chten:"));
}
}

});
}
});
}

所以我的问题是,如果我点击该项目什么也没有发生。他们不分享信息。如果我更改 name.equals 以定位它是有效的,但他们向我显示了错误的共享文本。而且只有在我搜索该项目时它才有效。

感谢您的帮助。

最佳答案

改变:

String name = adapter.getItem(position);

与:

String name = (String)arg0.getItemAtPosition(position);

关于android - Listview Onitemclick 没有任何反应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30054084/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com