這裏是我的Java:如何製作某個自定義的listview項目,發送給某個活動?
public class Cantos extends AppCompatActivity {
ListView lv;
Context context;
ArrayList cantoList;
public static String[] cantos = {"1: Abre Tu Oido", "2: A Cristo Quiero", "3: Acerquese Mi Clamor", "4: A Cristo Yo Alabare",
"5: Acude Dios", "6: Adelante", "7: A Dios Canto", "8: Adios Para Siempre", "9: Ahora Senor", "10: A Jesucristo Ven",
"11: Alabad A Dios"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_cantos);
initTypeface();
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle(null);
toolbar.setNavigationIcon(getDrawable(R.drawable.abc_ic_ab_back_mtrl_am_alpha));
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(Cantos.this, MainMenu.class);
startActivity(i);
}
});
}
private void initTypeface() {
Typeface myTypeface = Typeface.createFromAsset(getAssets(), "fonts/AftaSerifThin-Regular.otf");
TextView text = (TextView) findViewById(R.id.toolbarCantos);
text.setTypeface(myTypeface);
}
}
這是我其他的Java與BaseAdapter(自定義的ListView):
public class CustomAdapter extends BaseAdapter {
String[] result;
Context context;
private static LayoutInflater inflater = null;
public CustomAdapter(Cantos cantos, String[] cantos1) {
result = cantos1;
context = cantos;
inflater = (LayoutInflater)context.
getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
return result.length;
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
public class Holder
{
TextView tv;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Holder holder = new Holder();
View rowView;
rowView = inflater.inflate(R.layout.cantos_list, null);
holder.tv = (TextView) rowView.findViewById(R.id.textCanto);
holder.tv.setText(result[position]);
Typeface myFont = Typeface.createFromAsset(context.getAssets(), "fonts/AftaSerifThin-Regular.otf");
holder.tv.setTypeface(myFont);
return rowView;
}
}
我怎樣才能讓一個特定的項目送我到另一一定的活動? 提前謝謝! 對不起,如果我垃圾郵件太多!我幾乎完成了一些基礎知識!我求求你應付我!
需要更多信息。什麼項目會導致新的活動?你的listview在哪裏聲明。適配器在哪裏使用? – Samnon
項目「1 Abre Tu Oido」和哎呀!對不起,我刪除了意外的代碼。這裏是'context = this; lv =(ListView)findViewById(R.id.ListView); lv.setAdapter(new CustomAdapter(this,cantos));' – Alex