I have made a list of coctails and i want it to open a new window(with description and a photo) when i click one of the items... How should I proceed? Here is my code.. Thanks in advance. I am currrently using eclipse adt bundle 64 bit
MainActivity.java
`
`package bulku.yuki;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.app.Activity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
import android.app.ListActivity;
@SuppressWarnings("unused")
public class MainActivity extends ListActivity
{
String[] Koktail = {
"Mohito",
"Sex On the Beach",
"Gibson",
"Singapore Sling",
"Bahama Mama",
"Cuba Libre",
"Hurricane ",
"Bloody Mary",
"Kamikaze",
"Brandy Alexander",
"Fuzzy Navel"
};
Integer[] imageIDs = {
R.drawable.pic1,
R.drawable.pic2,
R.drawable.pic3,
R.drawable.pic4,
R.drawable.pic5,
R.drawable.pic6,
R.drawable.pic7,
R.drawable.pic8,
R.drawable.pic9,
R.drawable.pic10,
R.drawable.pic11
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/*
this.setListAdapter(new ArrayAdapter<String>(
this,
R.layout.lvrowlayout,
R.id.txtPresidentName,
presidents));
*/
//---using custom array adapter---
CustomArrayAdapter adapter = new
CustomArrayAdapter(this, Koktail, imageIDs);
setListAdapter(adapter);
}
}
activity_main.xml
<RelativeLayout xmlns:android="http://ift.tt/nIICcg"
xmlns:tools="http://ift.tt/LrGmb4"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView
android:id="@+id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</RelativeLayout>
Ivrowlayout.xml
<LinearLayout xmlns:android="http://ift.tt/nIICcg"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<ImageView
android:id="@+id/icon"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:src="@drawable/ic_launcher" />
<TextView
android:id="@+id/txtPresidentName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp" />
</LinearLayout>
Ivrowlayout2.xml
<LinearLayout xmlns:android="http://ift.tt/nIICcg"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<ImageView
android:id="@+id/icon"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:src="@drawable/ic_launcher" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="90dp"
android:orientation="vertical" >
<TextView
android:id="@+id/txtPresidentName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="25sp" />
<TextView
android:id="@+id/txtDescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp" />
</LinearLayout>
</LinearLayout>
CustomArrayAdapter.java
package bulku.yuki;
import android.app.Activity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
public class CustomArrayAdapter extends ArrayAdapter<String>{
private final Activity context;
private final String[] Koktail;
private final Integer[] imageIds;
public CustomArrayAdapter(Activity context,
String[] Koktail, Integer[] imageIds) {
super(context, R.layout.lvrowlayout2, Koktail);
this.context = context;
this.Koktail = Koktail;
this.imageIds = imageIds;
}
@Override
public View getView(int position, View view, ViewGroup parent) {
//---print the index of the row to examine---
Log.d("CustomArrayAdapter",String.valueOf(position));
LayoutInflater inflater = context.getLayoutInflater();
View rowView= inflater.inflate(R.layout.lvrowlayout2, null, true);
//---get a reference to all the views on the xml layout---
TextView txtTitle = (TextView) rowView.findViewById(R.id.txtKoktailName);
TextView txtDescription = (TextView)
rowView.findViewById(R.id.txtDescription);
ImageView imageView = (ImageView) rowView.findViewById(R.id.icon);
//---customize the content of each row based on position---
txtTitle.setText(Koktail[position]);
txtDescription.setText(Koktail[position] + "Shiko me shume");
imageView.setImageResource(imageIds[position]);
return rowView;
}
}
No comments:
Post a Comment