我有这段代码:
import android.app.Activity;
import android.app.ListActivity;
import android.os.Bundle;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class Bookmarks extends ListActivity{
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.bookmarks);
Database info=new Database(this);
info.open();
String data=info.getData();
String[] data_array = data.split(",");
info.close();
ListView listView1 = (ListView) findViewById(R.id.list_mia);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, data_array);
listView1.setAdapter(adapter);
listView1.setOnItemClickListener(){
public void onItemClick(AdapterView<?> a, View v, int position, long id){
if(data_array[position].startsWith("http://")){
//do this
}else{
//do this
}
}
}
}
}
工作正常。 如果它有一个网址,我如何使该项目可以解决? 我已经尝试过各种各样的帮助,因为我不能让它发挥作用! 感谢
答案 0 :(得分:0)
试试这个
listView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
if(data_array[position].startsWith("http://")){
//do this
}
else{
//do this
}
}
});