Я хочу добавить Listview в мой список.Это как простая книга путешествий.Пользователь собирается щелкнуть одну из стран и перейти к другому списку.Я легко могу объяснить это с помощью изображения
Это мой Listview
: http://prntscr.com/mhwic4
Я хочу добавить город для всех стран.Как Рим, Венеция, Флоренция в Италию, Сидней в Австралию, Рио в Бразилию что-то в этом роде.
Вот мои основные коды активности:
public class MainActivity extends AppCompatActivity {
ListView listView;
String[] nameArray = {"İtalya","Almanya","Amerika","Avustralya","Brezilya","Çin","Dubai","Fransa","İsviçre","Hollanda","İspanya","Kanada","Macaristan","Rusya",
"Sırbistan","Yunanistan"};
String[] infoArray = {
"Buon divertimento!",
"Viel spaß",
"Have fun!",
"Have fun!",
"Divirta-se!",
"玩得开心!",
"استمتع!",
"Amusez vous bien!",
"Viel spaß",
"Veel plezier!",
"Diviertete!",
"Have fun!",
"Jó szórakozást!",
"Веселись!",
"Забавите се!",
"Διασκεδάστε!"
};
Integer[] imageArray = {R.drawable.italy,
R.drawable.germany,
R.drawable.usa,
R.drawable.aus,
R.drawable.brazil,
R.drawable.china,
R.drawable.dubai,
R.drawable.france,
R.drawable.swit,
R.drawable.netherlands,
R.drawable.spain,
R.drawable.canada,
R.drawable.macaristan,
R.drawable.russia,
R.drawable.serbia,
R.drawable.greece
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
CustomListAdapter whatever = new CustomListAdapter(this, nameArray, infoArray, imageArray);
listView = (ListView) findViewById(R.id.listviewID);
listView.setAdapter(whatever);
}
}
вот код адаптера:
public class CustomListAdapter extends ArrayAdapter {
public View getView(int position, View view, ViewGroup parent) {
LayoutInflater inflater=context.getLayoutInflater();
View rowView=inflater.inflate(R.layout.listview_row, null,true);
//this code gets references to objects in the listview_row.xml file
TextView nameTextField = (TextView) rowView.findViewById(R.id.nameTextViewID);
TextView infoTextField = (TextView) rowView.findViewById(R.id.infoTextViewID);
ImageView imageView = (ImageView) rowView.findViewById(R.id.imageView1ID);
//this code sets the values of the objects to values from the arrays
nameTextField.setText(nameArray[position]);
infoTextField.setText(infoArray[position]);
imageView.setImageResource(imageIDarray[position]);
return rowView;
}
//to reference the Activity
private final Activity context;
//to store the animal images
private final Integer[] imageIDarray;
//to store the list of countries
private final String[] nameArray;
//to store the list of countries
private final String[] infoArray;
public CustomListAdapter(Activity context, String[] nameArrayParam, String[] infoArrayParam, Integer[] imageIDArrayParam) {
super(context, R.layout.listview_row, nameArrayParam);
this.context=context;
this.imageIDarray = imageIDArrayParam;
this.nameArray = nameArrayParam;
this.infoArray = infoArrayParam;
}
}