我有一个搜索活动,我有一个ListView,我在每个项目上显示标题,图标等,你可以搜索每一个。 实际上,当我点击一个项目时,打开一个带有文本视图和图像视图的“空白活动”,它会随着相应的标题和图像而变化。 但现在我想要更改它,我想在每个项目点击时打开一个特定的活动。
这是我的实际代码:
public class Buscar extends Activity {
// Declare Variables
ListView list;
ListViewAdapter adapter;
EditText editsearch;
String[] rank;
String[] country;
String[] population;
int[] crafteo;
int[] flag;
int[] actividad;
ArrayList<WorldPopulation> arraylist = new ArrayList<WorldPopulation>();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.listview_main);
// Generate sample data
rank = new String[] { "Armaduras", "Armaduras", "Armaduras", "Armaduras", "Armaduras", "Comida", "Comida","Comida",
"Comida",
"Comida",
"Comida",
"Comida",
"Comida",
"Comida",
"Comida",
"Comida", "Informativos","Informativos","Informativos","Informativos","Informativos", "Items","Items","Items","Items",
"Items","Items","Items","Items","Items","Items","Items","Items","Items","Items","Items", "Armas","Armas",
"Armas","Armas","Armas","Armas","Armas","Vehiculos","Vehiculos","Vehiculos","Vehiculos","Vehiculos",
"Utilidades","Utilidades","Utilidades","Utilidades","Utilidades","Utilidades","Utilidades","Herramientas",
"Herramientas","Herramientas","Herramientas","Herramientas","Herramientas","Herramientas","Herramientas",
"Herramientas","Herramientas","Mecanismos","Mecanismos","Mecanismos","Mecanismos","Mecanismos","Mecanismos",
"Mecanismos","Mecanismos","Mecanismos","Mecanismos","Mecanismos","Mecanismos","Mecanismos","Mecanismos",
"Mecanismos","Mecanismos","Mecanismos",
};
country = new String[] { "Casco", "Peto", "Perneras",
"Botas", "Armadura Caballo", "Pan", "Pastel",
"Pollo cocido",
"Pescado Cocido",
"Chuleta cerdo C.",
"Galleta",
"Manzana Dorada",
"Zanahoria dorada",
"Sopa champiñones",
"Tarta calabaza",
"Filete",
"Libro y Pluma",
"Reloj",
"Brujula",
"Mapa",
"Libro Escrito",
"Cama",
"Polvo Llamas",
"Vara de Llama",
"Cuenco",
"Ladrillo",
"Carbón Vegetal",
"Ojo de Ender",
"Lingote de oro",
"Lingote de hierro",
"Marco de Objetos",
"Cuadro",
"Papel",
"Palo",
"Cartel",
"Antorcha",
"Espada Diamante",
"Espada Oro",
"Espada Hierro",
"Espada Piedra",
"Espada Madera",
"Arco",
"Flecha",
"Vagoneta",
"Vagoneta con Horno",
"Vagoneta de Mercancias",
"Bote",
"Silla de Montar",
"Mesa de Trabajo",
"Cofre",
"Mesa Encantamientos",
"Valla",
"Puerta de Valla",
"Horno",
"Escalera",
"Pico",
"Hacha",
"Pala",
"Azada",
"Cubo",
"Mechero",
"Carga Ignea",
"Frasco de Cristal",
"Caña de Pescar",
"Cizallas",
"Rail Detecetor",
"Dispensador",
"Puerta de Hierro",
"Palanca",
"Caja de Musica",
"Piston",
"Piston Pegajoso",
"Rail Propulsor",
"Rail",
"Lampara de Redstone",
"Repetidor",
"Antorcha Redstone",
"Boton",
"Placa de Presion",
"TNT",
"Puerta",
"Trampilla",
};
population = new String[] { "Normal", "Normal",
"Normal", "Normal","Normal","Normal","Normal","Normal","Normal","Normal","Normal",
"Normal","Normal","Normal","Normal","Normal","Normal","Normal","Normal","Normal","Normal",
"Normal","Normal","Normal","Normal","Normal","Normal","Normal","Normal","Normal","Normal",
"Normal","Normal","Normal","Normal","Normal","Normal","Normal","Normal","Normal","Normal",
"Normal","Normal","Normal","Normal","Normal","Normal","Normal","Normal","Normal","Normal",
"Normal","Normal","Normal","Normal","Normal","Normal","Normal","Normal","Normal","Normal",
"Normal","Normal","Normal","Normal","Normal","Normal","Normal","Normal","Normal","Normal",
"Normal","Normal","Normal","Normal","Normal","Normal","Normal","Normal","Normal","Normal",
"Normal",};
flag = new int[] { R.drawable.casco, R.drawable.armadura,
R.drawable.pernera, R.drawable.botas,
R.drawable.caballo, R.drawable.pan, R.drawable.pastel,
R.drawable.polloc,
R.drawable.pezc,
R.drawable.ccerdoc,
R.drawable.galleta,
R.drawable.manzanad,
R.drawable.zanahoriad,
R.drawable.sopac,
R.drawable.tartac,
R.drawable.filete,
R.drawable.libropluma,
R.drawable.relojc,
R.drawable.brujula,
R.drawable.mapa,
R.drawable.libro,
R.drawable.cama,
R.drawable.pllamas,
R.drawable.vllama,
R.drawable.cuenco,
R.drawable.ladrillo,
R.drawable.carbonv,
R.drawable.ojoe,
R.drawable.lingoteo,
R.drawable.lingoteh,
R.drawable.marcoo,
R.drawable.cuadro,
R.drawable.papel,
R.drawable.palo,
R.drawable.cartel,
R.drawable.antorcha,
R.drawable.espadad,
R.drawable.espadao,
R.drawable.espadah,
R.drawable.espadap,
R.drawable.espadam,
R.drawable.arco,
R.drawable.flecha,
R.drawable.vagoneta,
R.drawable.vagonetah,
R.drawable.vagonetam,
R.drawable.bote,
R.drawable.sillam,
R.drawable.mtrabajo,
R.drawable.cofre,
R.drawable.mencantamientos,
R.drawable.valla,
R.drawable.pvalla,
R.drawable.horno,
R.drawable.escalera,
R.drawable.picod,
R.drawable.hachad,
R.drawable.palad,
R.drawable.azadad,
R.drawable.cubo,
R.drawable.mechero,
R.drawable.cignea,
R.drawable.fcristal,
R.drawable.cpescar,
R.drawable.cizallas,
R.drawable.raild,
R.drawable.dispensador,
R.drawable.puertah,
R.drawable.palanca,
R.drawable.cajam,
R.drawable.piston,
R.drawable.pistonp,
R.drawable.railp,
R.drawable.rail,
R.drawable.lamparar,
R.drawable.repetidor,
R.drawable.antorchar,
R.drawable.boton,
R.drawable.placap,
R.drawable.tnt,
R.drawable.puerta,
R.drawable.trampilla,
};
crafteo = new int[] { R.drawable.icasco, R.drawable.ipeto,
R.drawable.ipernera, R.drawable.ibotas,
R.drawable.icaballo, R.drawable.ipan, R.drawable.ipastel,
R.drawable.ipolloc,
R.drawable.ipezc,
R.drawable.iccerdoc,
R.drawable.igalleta,
R.drawable.imanzanad,
R.drawable.izanahoriad,
R.drawable.isopac,
R.drawable.itartac,
R.drawable.ifilete,
R.drawable.ilibropluma,
R.drawable.irelojt,
R.drawable.ibrujula,
R.drawable.imapa,
R.drawable.libro,
R.drawable.icama,
R.drawable.ipllamas,
R.drawable.icono,
R.drawable.icuenco,
R.drawable.iladrillos,
R.drawable.icarbonv,
R.drawable.iojoe,
R.drawable.ilingoteo,
R.drawable.ilingoteh,
R.drawable.imarcoo,
R.drawable.icuadro,
R.drawable.ipapel,
R.drawable.ipalo,
R.drawable.icartel,
R.drawable.iantorcha,
R.drawable.iespadad,
R.drawable.iespadao,
R.drawable.iespadah,
R.drawable.iespadap,
R.drawable.iespadam,
R.drawable.iarco,
R.drawable.iflecha,
R.drawable.ivagoneta,
R.drawable.ivagonetah,
R.drawable.ivagonetam,
R.drawable.ibote,
R.drawable.isillam,
R.drawable.imtrabajo,
R.drawable.icofre,
R.drawable.imencantamientos,
R.drawable.ivalla,
R.drawable.ipvalla,
R.drawable.ihorno,
R.drawable.iescalera,
R.drawable.ipicod,
R.drawable.ihachad,
R.drawable.ipalad,
R.drawable.iazadad,
R.drawable.icubo,
R.drawable.imechero,
R.drawable.icignea,
R.drawable.ifcristal,
R.drawable.icpescar,
R.drawable.icizallas,
R.drawable.iraild,
R.drawable.idispensador,
R.drawable.ipuertah,
R.drawable.ipalanca,
R.drawable.icajam,
R.drawable.ipiston,
R.drawable.ipistonp,
R.drawable.irailp,
R.drawable.irail,
R.drawable.ilamparar,
R.drawable.irepetidor,
R.drawable.iantorchar,
R.drawable.iboton,
R.drawable.iplacap,
R.drawable.itnt,
R.drawable.ipuerta,
R.drawable.itrampilla,
};
// Locate the ListView in listview_main.xml
list = (ListView) findViewById(R.id.listview);
for (int i = 0; i < rank.length; i++)
{
WorldPopulation wp = new WorldPopulation(rank[i], country[i],
population[i], flag[i], crafteo[i]);
// Binds all strings into an array
arraylist.add(wp);
}
// Pass results to ListViewAdapter Class
adapter = new ListViewAdapter(this, arraylist);
// Binds the Adapter to the ListView
list.setAdapter(adapter);
// Locate the EditText in listview_main.xml
editsearch = (EditText) findViewById(R.id.search);
// Capture Text in EditText
editsearch.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub
String text = editsearch.getText().toString().toLowerCase(Locale.getDefault());
adapter.filter(text);
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1,
int arg2, int arg3) {
// TODO Auto-generated method stub
}
@Override
public void onTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
// TODO Auto-generated method stub
}
});
}
}
答案 0 :(得分:0)
尝试:
list1.setOnItemClickListener(
new OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> arg0, View view,
int position, long id) {
TextView _countryTextView = (TextView) view.findViewById(R.id.countrylabel);
Intent myIntent;
if(_countryTextView.getText().equals("fish"))
{
myIntent = new Intent(CurrentActivity.this, Fish.class);
}
CurrentActivity.this.startActivity(myIntent);
}
}
);
在manifest.xml中定义新的Activity
<activity android:label="@string/app_name" android:name="com.package.project.NextActivityName" />