我必须先在功能开始之前提供所有链接,如果我点击ListView
中的项目,则必须转到该视频链接,现在我在ListView
的持有者中提供了链接,它看起来不太好,如果我点击ListView
中的第一项,它将采用第一个链接,就像我需要的那样。
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main1);
ArrayList<Recipedetails1> image_details = GetSearchResults();
final ListView lv1 = (ListView) findViewById(R.id.listV1_main);
lv1.setAdapter(new ItemListBaseAdapter1(this, image_details));
lv1.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> a, View v, int position, long id) {
Object o = lv1.getItemAtPosition(position);
Recipedetails1 obj_itemDetails = (Recipedetails1)o;
final Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(((Recipedetails1) o).getUrlWiki()));
startActivity(i);
}
});
}
private ArrayList<Recipedetails1> GetSearchResults(){
ArrayList<Recipedetails1> results = new ArrayList<Recipedetails1>();
Recipedetails1 item_details = new Recipedetails1();
item_details.setName1("Vegterian");
item_details.setItemDescription1("Recipes made by raw materials");
item_details.setUrlWiki("https://www.youtube.com/watch?v=C_r0mFvMSfU");
item_details.setImageNumber1(1);
results.add(item_details);
item_details = new Recipedetails1();
item_details.setName1("Non-Vegterian");
item_details.setItemDescription1("Flesh of sweet animals");
item_details.setUrlWiki("https://www.youtube.com/watch?v=C_r0mFvMSfU");
item_details.setImageNumber1(2);
results.add(item_details);
item_details = new Recipedetails1();
item_details.setName1("Pickels");
item_details.setItemDescription1("Touchable dish by Homemade");
item_details.setUrlWiki("https://www.youtube.com/watch?v=C_r0mFvMSfU");
item_details.setImageNumber1(3);
results.add(item_details);
item_details = new Recipedetails1();
item_details.setName1("Soups");
item_details.setItemDescription1("Startup for our food");
item_details.setUrlWiki("https://www.youtube.com/watch?v=C_r0mFvMSfU");
item_details.setImageNumber1(4);
results.add(item_details);
return results;
}
实际上我不需要这样的方式,因为它看起来不太好,我希望我的链接没有显示,它必须在ListView中单击项目后工作,实际上在我的代码中,单击项目后它将去,但它将需要从我的持有人链接这是任何其他方式给予link.this代码方法看起来不好,我不需要我的持有人想要显示我的链接
答案 0 :(得分:2)
现在我的代码正常工作,我在我的列表适配器中删除了url wiki的持有者,现在看起来很好并且正在工作,我评论这行// holder.recipeLinkWiki.setText(itemDetailsrrayList1.get(position).getUrlWiki( ));
答案 1 :(得分:1)
您可以通过点击位置从image_details
数组列表中获取链接。 image_details.get(position).getUrlWiki();
像这样使用:
ArrayList<Recipedetails1> image_details;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main1);
image_details = GetSearchResults();
final ListView lv1 = (ListView) findViewById(R.id.listV1_main);
lv1.setAdapter(new ItemListBaseAdapter1(this, image_details));
lv1.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> a, View v, int position, long id) {
//int pos = lv1.getItemAtPosition(position);
String link = image_details.get(position).getUrlWiki();
final Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(link));
startActivity(i);
}
});
}