0

这是否可以将链接作为数组提供,我们可以根据列表项的相应链接获取链接,在我的代码中,我将硬编码我的链接看起来不太好,我需要什么我想提供所有链接一个数组,单击列表视图中的项目后,它必须打开各自的链接。

public class SouthIndianvegrecipes  extends Activity  {

    //private Button Manual;

    @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;
                Toast.makeText(SouthIndianvegrecipes.this, "You have chosen : " + " " + obj_itemDetails.getName1(), Toast.LENGTH_LONG).show();


            } 
        });
    }

    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;
    }
}

我想点击列表中的项目,它必须去他们各自的视频链接,但现在我将它放在持有人中,它会直接显示链接,它看起来不太好。

4

1 回答 1

2

只需启动视频的意图。这应该有效:

@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(o.getUrlWiki()));
  startActivity(i);
} 
于 2013-03-09T10:22:07.850 回答