public class ShotDrinks extends ActionBarActivity {
String title[] = new String[]{"Б-52","Зеленый мексиканец","Оборотень","Аут","БМВ"};
String description[] = new String[]{"Бейлис, калуа, трипл сек","Текила, лимонный сок, пизан","лалалалал","Виски, коньяк, водка, самбука","текила, трипл сек, самбука"};
int[] icons = new int [] {R.drawable.b52, R.drawable.green_mexicano, R.drawable.oboroten, R.drawable.ayt, R.drawable.bmw};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.shot_drinks);
// Связываемся с ListView
ListView list = (ListView) findViewById(R.id.lvMain);
// создаем адаптер
ArrayAdapter adapter = new ArrayAdapter
(this, android.R.layout.simple_list_item_1, title);
// устанавливаем адаптер списку
list.setAdapter(adapter);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
onShowDialog(title[position], description[position], icons[position]);
}
});
}
public void onShowDialog(String title, String message, int drawable){
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(title)
.setMessage(message)
.setCancelable(true)
.setIcon(drawable)
.setNegativeButton("Закрыть", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
})
.setPositiveButton ("Поделиться", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
final Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT, "_SUBJECT_");
intent.putExtra(Intent.EXTRA_TEXT, "_BODY_");
startActivity(Intent.createChooser(intent, getString(R.string.app_name)));
}
});
AlertDialog alert = builder.create();
alert.show();
}
}