我从一个包含更改项目的数组列表中填充了一个列表视图。所以我不知道任何立场。
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, results);
listview1.setAdapter(arrayAdapter);
我想点击一个项目并链接Go google图片并将该项目作为搜索词。
答案 0 :(得分:2)
如果您的列表是Urls数组,那么请尝试这样,
public class SampleListActivity extends ListActivity {
static final String[] URLS = new String[] { "http://music.com", "http://yahoo.com", "http://etc.com","http://etc1.com","http://etc2.com"};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(this, R.layout.yourlayout,
URLS));
final ListView listView = getListView();
listView.setTextFilterEnabled(true);
listView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
String selectedUrl= URLS[position];
Uri uri = Uri.parse(selectedUrl);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
});
}
}
答案 1 :(得分:0)
您可以使用此功能打开网页。
Uri uri = Uri.parse("http://www.google.com");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
答案 2 :(得分:0)
您只需为listView实现 OnItemClickListener() 。
像:
yourlistView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
// Here arg2 is a Postion
}
});