krishnaveni
Well-Known Member
I have to develop one android application.
Here i have to create gridview...In gridview layout have one textview and one gallery view...In these gallery view have one imageview and one textview...
These is my main_activity.xml file:
[HIGH]<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF"
android
rientation="vertical">
<GridView
android:id="@+id/listView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF"
/>
</RelativeLayout>
[/HIGH]list_item.xml:
[HIGH]<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android
rientation="vertical"
>
<Gallery
android:id="@+id/model"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/brand"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#CC0033"
android:textSize="16sp"
android:textStyle="bold" />
</LinearLayout>
[/HIGH]gallery_item.xml:
[HIGH] <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android
rientation="vertical"
>
<ImageView
android:id="@+id/model1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/articletitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#CC0033"
android:textSize="16sp"
android:textStyle="bold" />
</LinearLayout>
[/HIGH]This is my adpater java file:
[HIGH] public class CustomListViewAdapter extends ArrayAdapter<Laptop> {
Activity context;
List<Laptop> laptops;
public CustomListViewAdapter(Context context2, List<Laptop> laptops) {
super(context2, R.layout.list_item, laptops);
this.context = (Activity) context2;
this.laptops = laptops;
}
/*private view holder class*/
private class ViewHolder {
ImageView imageView;
Gallery txtModel;
TextView txtBrand;
TextView txtPrice;
}
public Laptop getItem(int position) {
return laptops.get(position);
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
LayoutInflater inflater = context.getLayoutInflater();
if (convertView == null) {
convertView = inflater.inflate(R.layout.list_item, null);
holder = new ViewHolder();
holder.txtModel = (Gallery) convertView.findViewById(R.id.model);
holder.txtBrand = (TextView) convertView.findViewById(R.id.brand);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
listViewAdapter = new ListAdapter(context, laptops);
Laptop laptop = (Laptop) getItem(position);
holder.txtModel.setAdapter(listViewAdapter);
holder.txtBrand.setText(laptop.getBrand());
return convertView;
}
}
[/HIGH]
This is my ListAdapter.java class:
[HIGH]public class ListAdapter extends ArrayAdapter<Laptop> {
Activity context;
List<Laptop> laptops;
public ListAdapter(Activity context, List<Laptop> laptops) {
super(context, R.layout.listrow, laptops);
this.context = context;
this.laptops = laptops;
}
/*private view holder class*/
private class ViewHolder {
ImageView imageView;
TextView txtModel;
TextView txtBrand;
TextView txtPrice;
}
public Laptop getItem(int position) {
return laptops.get(position);
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
LayoutInflater inflater = context.getLayoutInflater();
if (convertView == null) {
convertView = inflater.inflate(R.layout.listrow, null);
holder = new ViewHolder();
holder.txtModel = (TextView) convertView.findViewById(R.id.articletitle);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
Laptop laptop = (Laptop) getItem(position);
holder.txtModel.setText(laptop.getModel());
return convertView;
}
[/HIGH]
I have to run the app means am getting the category name well...also all article title is displayed on each and every category many times..
Why this is displayed like :
please give me the solution for these ???
Here i have to create gridview...In gridview layout have one textview and one gallery view...In these gallery view have one imageview and one textview...
These is my main_activity.xml file:
[HIGH]<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF"
android
rientation="vertical"><GridView
android:id="@+id/listView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF"
/>
</RelativeLayout>
[/HIGH]list_item.xml:
[HIGH]<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android
rientation="vertical">
<Gallery
android:id="@+id/model"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/brand"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#CC0033"
android:textSize="16sp"
android:textStyle="bold" />
</LinearLayout>
[/HIGH]gallery_item.xml:
[HIGH] <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android
rientation="vertical">
<ImageView
android:id="@+id/model1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/articletitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#CC0033"
android:textSize="16sp"
android:textStyle="bold" />
</LinearLayout>
[/HIGH]This is my adpater java file:
[HIGH] public class CustomListViewAdapter extends ArrayAdapter<Laptop> {
Activity context;
List<Laptop> laptops;
public CustomListViewAdapter(Context context2, List<Laptop> laptops) {
super(context2, R.layout.list_item, laptops);
this.context = (Activity) context2;
this.laptops = laptops;
}
/*private view holder class*/
private class ViewHolder {
ImageView imageView;
Gallery txtModel;
TextView txtBrand;
TextView txtPrice;
}
public Laptop getItem(int position) {
return laptops.get(position);
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
LayoutInflater inflater = context.getLayoutInflater();
if (convertView == null) {
convertView = inflater.inflate(R.layout.list_item, null);
holder = new ViewHolder();
holder.txtModel = (Gallery) convertView.findViewById(R.id.model);
holder.txtBrand = (TextView) convertView.findViewById(R.id.brand);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
listViewAdapter = new ListAdapter(context, laptops);
Laptop laptop = (Laptop) getItem(position);
holder.txtModel.setAdapter(listViewAdapter);
holder.txtBrand.setText(laptop.getBrand());
return convertView;
}
}
[/HIGH]
This is my ListAdapter.java class:
[HIGH]public class ListAdapter extends ArrayAdapter<Laptop> {
Activity context;
List<Laptop> laptops;
public ListAdapter(Activity context, List<Laptop> laptops) {
super(context, R.layout.listrow, laptops);
this.context = context;
this.laptops = laptops;
}
/*private view holder class*/
private class ViewHolder {
ImageView imageView;
TextView txtModel;
TextView txtBrand;
TextView txtPrice;
}
public Laptop getItem(int position) {
return laptops.get(position);
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
LayoutInflater inflater = context.getLayoutInflater();
if (convertView == null) {
convertView = inflater.inflate(R.layout.listrow, null);
holder = new ViewHolder();
holder.txtModel = (TextView) convertView.findViewById(R.id.articletitle);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
Laptop laptop = (Laptop) getItem(position);
holder.txtModel.setText(laptop.getModel());
return convertView;
}
[/HIGH]
I have to run the app means am getting the category name well...also all article title is displayed on each and every category many times..
Why this is displayed like :
please give me the solution for these ???