【发布时间】:2014-08-07 15:47:10
【问题描述】:
这是我的代码
我想添加此方法但是,我会避免它们在每次单击按钮时出现相同的 url
所以我希望每个点击的按钮都会改变要显示的网址
我想添加这段代码
mylist.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View v, int position, long id) {
if (position == 1)
{
Intent myIntent = new Intent(getApplicationContext(), SecondaActivity.class);
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("URL")));
}
else if (position == 2)
{Intent myIntent = new Intent(getApplicationContext(), SecondaActivity.class);
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("URL")));
活动A
ArrayList<String> bottone;
Button b1,b2,b3,b4,b5,b6,b7,b8,b9,b10;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//creazione fullscreen activity
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.gruppipuntate_activity);
//rimozione action bar
if (Build.VERSION.SDK_INT < 11){
getSupportActionBar().hide();
b1 = (Button) findViewById (R.id.button1);
b2 = (Button) findViewById (R.id.button2);
b3 = (Button) findViewById (R.id.button3);
b4 = (Button) findViewById (R.id.button4);
b5 = (Button) findViewById (R.id.button5);
b6 = (Button) findViewById (R.id.button6);
b7 = (Button) findViewById (R.id.button7);
b8 = (Button) findViewById (R.id.button8);
b9 = (Button) findViewById (R.id.button9);
b10 = (Button) findViewById (R.id.button10);
b1.setOnClickListener(this);
b2.setOnClickListener(this);
b3.setOnClickListener(this);
b4.setOnClickListener(this);
b5.setOnClickListener(this);
b6.setOnClickListener(this);
b7.setOnClickListener(this);
b8.setOnClickListener(this);
b9.setOnClickListener(this);
b10.setOnClickListener(this);
}
}
//gestione Switch java per selezione puntate
public void onClick(View v) {
String[] Product;
Intent episodi = new Intent(GruppiPuntateActivity.this, EpisodiActivity.class);
switch(v.getId()){
case R.id.button1:
Product = new String[]{"ciao", "1", "bottone"};
episodi.putExtra("Product", Product);
startActivity(episodi);
break;
case R.id.button2:
Product = new String[]{"ciao", "2", "bottone"};
episodi.putExtra("Product", Product);
startActivity(episodi);
break;
case R.id.button3:
Product = new String[]{"ciao", "3", "bottone"};
episodi.putExtra("Product", Product);
startActivity(episodi);
break;
case R.id.button4:
Product = new String[]{"asd", "seco", "tezo"};
episodi.putExtra("Product", Product);
startActivity(episodi);
break;
case R.id.button5:
Product = new String[]{"primo", "secondo", "terzo"};
episodi.putExtra("Product", Product);
startActivity(episodi);
break;
case R.id.button6:
Product = new String[]{"primo", "secondo", "terzo"};
episodi.putExtra("Product", Product);
startActivity(episodi);
break;
case R.id.button7:
Product = new String[]{"primo", "secondo", "terzo"};
episodi.putExtra("Product", Product);
startActivity(episodi);
break;
case R.id.button8:
Product = new String[]{"primo", "secondo", "terzo"};
episodi.putExtra("Product", Product);
startActivity(episodi);
break;
case R.id.button9:
Product = new String[]{"primo", "secondo", "terzo"};
episodi.putExtra("Product", Product);
startActivity(episodi);
break;
case R.id.button10:
Product = new String[]{"primo", "secondo", "terzo"};
episodi.putExtra("Product", Product);
startActivity(episodi);
break;
}
}
活动 B
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//creazione fullscreen activity
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.episodi_activity);
final ListView mylist = (ListView) findViewById(R.id.listView1);
String[] PP = getIntent().getStringArrayExtra("Product");
final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, PP);
mylist.setAdapter(adapter);
mylist.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View v, int position, long id) {
if (position == 1)
{
Intent myIntent = new Intent(getApplicationContext(), EpisodiActivity.class);
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.dailymotion.com/video/x1zfa4i_camera-cafe-3-stagione-ep-240-crema-miracolosa_shortfilms")));
}
}
});
} }
【问题讨论】:
-
您的问题解决了吗?请不要忘记投票并接受对您最有帮助的答案。
-
别担心,我试试你的代码,如果它有效,你投票:)
标签: android arrays eclipse listview android-intent