我在我的应用中有gridview。我有6件物品。我想在点击项目时调用另一个动作。我该怎么做?这是我的代码。帮帮我吧 现在,当我点击项目时,我可以用吐司显示消息。但是我想要另外一个活动帮助我。
public class GridViewImageTextActivity extends AppCompatActivity {
GridView androidGridView;
String[] gridViewString = {
"Hesapla", "Geçmiş", "Paylaş", "Geribildirim", "Sıralama", "Beğen",
} ;
int[] gridViewImageId = {
R.drawable.hesap, R.drawable.gecmis, R.drawable.paylas, R.drawable.geribildirim, R.drawable.siralama, R.drawable.begen
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.grid_view_image_text);
CustomGridViewActivity adapterViewAndroid = new CustomGridViewActivity(GridViewImageTextActivity.this, gridViewString, gridViewImageId);
androidGridView=(GridView)findViewById(R.id.grid_view_image_text);
androidGridView.setAdapter(adapterViewAndroid);
androidGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int i, long id) {
Toast.makeText(GridViewImageTextActivity.this, "GridView Item: " + gridViewString[+i], Toast.LENGTH_LONG).show();
}
});
}
}
答案 0 :(得分:0)
您必须创建另一个活动的类,将此活动添加到AndroidManifest.xml
文件并从这样开始:
@Override
public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
Context context = GridViewImageTextActivity.this;
Intent intent = null;
switch (position) {
case 0:
intent = new Intent(context, FirstActivity.class);
startActivity(intent);
return;
case 1:
intent = new Intent(context, SecondActivity.class);
startActivity(intent);
return;
case 2:
// start another activity
return;
// and so on
}
}
答案 1 :(得分:0)
以下是前3个项目的示例代码
swithc(View v){case R.id.button1:startActivity(new Intent(GridViewImageTextActivity.this,ActivityB.clsss));break;case R.id.button2:startActivity(new Intent(GridViewImageTextActivity.this,ActivityC.clsss));break;case R.id.button3:startActivity(new Intent(GridViewImageTextActivity.this,ActivityD.clsss));break;}