2
I’m developing a small project in android studio where I have a listview where the data is introduced through an array. But what I need is, when the user selects some element from the list, based on the position of the element to load all the data in another Activity
class sending data (position)
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_noticias);
mAdapter = new NoticiasAdapter(Noticias.this, mList);
setListAdapter(mAdapter);
}
public void onResume() {
super.onResume();
preencherlista();
mAdapter.notifyDataSetChanged();
}
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
mList.get(position);
Intent intent = new Intent(getBaseContext(), NoticiasValor.class);
intent.putExtra("valor","position");
startActivity(intent);
}
public void preencherlista() {
mList.add(new NoticiasDados("Jose", "Maria"));
mList.add(new NoticiasDados("Maria","Alfredo"));
mList.add(new NoticiasDados("Luis","Sonia"));
}
}
class that receives and displays
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.noticas_valor_layout);
/*Intent mIntent = getIntent();
int intValue = mIntent.getIntExtra("valor",0);*/
int intValue= getIntent().getIntExtra("valor",0);
TextView a = (TextView) findViewById(R.id.txttitulo2);
a.setText(mList.get(intValue).getTitulo());
TextView b = (TextView) findViewById(R.id.txttexto2);
b.setText(mList.get(intValue).getTexto());
}
And what have you tried to do? What was the difficulty?
– Woss