Answer the question
In order to leave comments, you need to log in
ListView and transition to new activity: how?
There is a custom ListView:
<LinearLayout
… >
<ListView
android:id="@+id/listView1" >
</ListView>
</LinearLayout>
<TextView
android:id="@+id/text1" />
<TextView
android:id="@+id/text2" />
<Button
android:id="@+id/button1"/>
public class Spisok extends Activity {
private ArrayList<HashMap<String, Object>> Irr;
private static final String Form1 = "form1"; // Форма1
private static final String Form2 = "form2"; // Форма2
private static final String Form3 = "form3"; // Форма3
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_spisok);
setTitle("Irr");
ListView listView = (ListView) findViewById(R.id.listView1);
// создаем массив списков
Irr = new ArrayList<HashMap<String, Object>>();
HashMap<String, Object> hm;
hm = new HashMap<String, Object>();
hm.put(Form1, "некоторый текст 1");
hm.put(Form2, "некоторый текст 2");
hm.put(Form3, "некоторый текст 3");
Irr.add(hm);
hm = new HashMap<String, Object>();
hm.put(Form1, "некоторый текст 1");
hm.put(Form2, "некоторый текст 2");
hm.put(Form3, "некоторый текст 3");
Irr.add(hm);
SimpleAdapter adapter = new SimpleAdapter(this, Irr,
R.layout.list_item, new String[] { Form1, Form2, Form3 },
new int[] { R.id.text1, R.id.text2, R.id.text3 });
listView.setAdapter(adapter);
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<> arg0, View arg1, int position, long arg3) {
Intent intent = new Intent (this, SecondActivity.class );
intent.putExtra("key", "transferedText")
startActivity(intent);
} });
Answer the question
In order to leave comments, you need to log in
Learn wise men, figs who helped when they asked on 4 forums ...
listView.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
String key = ((TextView) view.findViewById(R.id.text1)).getText().toString();
Intent intent = new Intent(getApplicationContext(), Prob.class);
intent.putExtra(TAG_NAME, key);
startActivity(intent);
}
});
}
Intent intent = getIntent();
String Name = intent.getStringExtra(TAG_NAME);
Do not invent, there is no custom adapter or foliage.
If you had a custom adapter, you could just put a click on the button.
Try to hang a listener on the entire list, and see if it will send a copy of the button in the view (I never did this - but it suddenly works). If not, just write a full-fledged adapter.
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<> arg0, View arg1, int arg2,
long arg3) {
//возможно arg1 будет здесь кнопкой или текстом, хотя скорей всего всей вьюхой, но попробовать стоит
//если прокатит - arg2 - номер в массиве
}
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question