I make a CustomAdapter extends BaseAdapter.In it's getView() method , I use ViewHolder. And I set a clickListener with a TextView to set a view (call it A)gone and another view (call it B)visible , but when I click the TextView , the A GONE but it leave a space ,so the B cannot match the parent.
My code like
#Override
public View getView(int position, View convertView, ViewGroup parent) {
final ViewHolder viewHolder;
if (convertView == null){
convertView = mLayoutInflater.inflate(R.layout.customlayout,parent,false);
viewHolder = new ViewHolder();
}else {
viewHolder = (ViewHolder) convertView.getTag();
}
viewHolder.textView = (TextView) convertView.findViewById(R.id.textview);
viewHoler.a = (LinearLayout) convertView.findViewById(R.id.a);
viewHoler.b = (LinearLayout) convertView.findViewById(R.id.b);
viewHolder.textview.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (viewHolder.a.getVisibility() == View.GONE){
viewHolder.b.setVisibility(View.GONE);
viewHolder.a.setVisibility(View.VISIBLE);
notifyDataSetChanged();
}else {
viewHolder.a.setVisibility(View.GONE);
viewHolder.b.setVisibility(View.VISIBLE);
notifyDataSetChanged();
}
}
});
convertView.setTag(viewHolder);
return convertView;
}
the customlayout code is
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="150dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="#drawable/bg"/>
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"/>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="#+id/a"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:visibility="gone">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="button a"/>
</LinearLayout>
<LinearLayout
android:id="#+id/b"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:visibility="visible">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="button b"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
It should be show like this way when I click the textView
but it always like another way below , just like the A view still take the space ,that like call setVisibility(View.INVISIBLE) or not setVisibility(View.GONE)
the A view is not appear because that although B view has disappeared but it still take the space
Why will it behave like that? How should I do to solve it ?
Thank you for your help.
Try with wrap_content on your LinearLayouts.
Like this -
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="150dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="#drawable/bg"/>
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"/>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="#+id/a"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="gone">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="button a"/>
</LinearLayout>
<LinearLayout
android:id="#+id/b"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="visible">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="button b"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
Related
I have this ListView with an Adapter that extends BaseAdapter. Inside the
public View getView(final int position, View view, ViewGroup parent) {...}
I attach a clickListener to view like this:
view.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
final LinearLayout llMatchInfo = v.findViewById(R.id.matchInfo);
if (llMatchInfo == null) return;
llMatchInfo.setVisibility(llMatchInfo.getVisibility() == View.GONE ? View.VISIBLE : View.GONE);
}
});
Then I have this one user complaining that when he clicks an element llMatchInfo is visible for a split second and then disappears again.
This is the only place the matchInfo view has it's visibility changed.
Can anyone help me figure out why this is happening?
Thanks in advance
Here's the outer XML for each item in my ListView:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingEnd="5dp">
<LinearLayout
android:orientation="horizontal"
android:layout_width="10dp"
android:layout_height="fill_parent"
android:id="#+id/live_indicator">
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="#+id/match_data"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
...
</LinearLayout>
<include
android:layout_width="fill_parent"
android:layout_height="wrap_content"
layout="#layout/match_info"
android:id="#+id/matchInfo" />
</LinearLayout>
</LinearLayout>
And the inner XML for the actual matchInfo (the part I want to toggle visibility on):
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="gone">
<LinearLayout
android:id="#+id/team_logos"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="horizontal">
<ImageView
... />
<ImageView
... />
</LinearLayout>
<TextView
... />
<TextView
... />
<TextView
... />
<LinearLayout
android:id="#+id/tv_channels"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="horizontal"
android:visibility="visible">
<ImageView
... />
<ImageView
... />
</LinearLayout>
</LinearLayout>
This is not my first time implementing an adapter for a RecyclerView so I don't understand this issue.
I have the recycler view populating with items using a custom list item
I also have the Viewholder itemView.setOnClickListener set and when I click the item, it doesn't register the click.
But, when I click a little above the text on the item, it registers the click... Maybe something to do with my custom item layout?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:id="#+id/cardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/spacing_small"
android:layout_marginRight="#dimen/spacing_small"
android:layout_marginTop="#dimen/spacing_small">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/spacing_large"
android:clickable="true"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Plan ID:" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Username:" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Timestamp:" />
</LinearLayout>
<View
android:layout_width="#dimen/spacing_medium"
android:layout_height="0dp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical"
android:orientation="vertical">
<TextView
android:id="#+id/plan_id_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/username_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/timestamp_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<ImageButton
android:id="#+id/options"
android:layout_width="wrap_content"
android:layout_height="#dimen/spacing_xlarge"
android:background="?attr/selectableItemBackgroundBorderless"
android:tint="#color/grey_40"
app:srcCompat="#drawable/ic_more_vert" />
<View
android:layout_width="#dimen/spacing_small"
android:layout_height="0dp" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
Here is my Adapter:
#Override
public void onClick(View v) {
final TextView timestamp_tv = v.findViewById(R.id.timestamp_tv);
switch (form_name) {
case "daily_worksheet":
Bundle bundle = new Bundle();
bundle.putString("timestamp", timestamp_tv.getText().toString());
new LoadActivityTask((Activity) context, new Intent(context, DailyWorksheet_View.class), "Daily Worksheet Form", bundle).execute();
break;
default:break;
}
}
public class ViewHolder extends RecyclerView.ViewHolder {
private TextView plan_id, username, timestamp;
private ImageView options;
public ViewHolder(View itemView) {
super(itemView);
itemView.setOnClickListener(ReceiptAdapter.this);
plan_id = (TextView) itemView.findViewById(R.id.plan_id_tv);
username = (TextView) itemView.findViewById(R.id.username_tv);
timestamp = (TextView) itemView.findViewById(R.id.timestamp_tv);
options = (ImageView) itemView.findViewById(R.id.options);
}
}
I think the error is because you are setting the OnClickListener on the Root of your layout, and your CardView which is basically the main background of your layout is not clickable, so the only space which affect the OnClicklistener is the small margin of the CardView.
I think you should set the OnClicklistener on the Cardview (and set as clickable).
itemView.findViewById(R.id.cardView).setOnClickListener(ReceiptAdapter.this);
Try to delete android:clickable="true" in the first LinearLayout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:id="#+id/cardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/spacing_small"
android:layout_marginRight="#dimen/spacing_small"
android:layout_marginTop="#dimen/spacing_small">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/spacing_large"
android:orientation="horizontal">
...
I have edit button on toolbar on click this button i want to show new view that is cross button inside every row of listview. is this possible and if yes how ? Thanks in advance. Below is layout files:
main layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:background="#color/backgroundColor"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
android:background="#color/TabColor"
android:weightSum="10"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_weight="1"
android:onClick="back2"
android:layout_gravity="center"
app:srcCompat="#drawable/back_arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_weight="7"
android:paddingLeft="#dimen/margin_small"
android:text="List OF Hotels"
android:textSize="#dimen/text_title"
android:textColor="#color/WhiteColor"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<FrameLayout
android:layout_weight="2"
android:background="#drawable/transparent_bg"
android:layout_marginRight="#dimen/margin_large"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:id="#+id/edit_jobs"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_marginBottom="#dimen/margin_small"
android:layout_marginTop="#dimen/margin_small"
android:text="Edit"
android:textColor="#color/WhiteColor"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:visibility="invisible"
android:id="#+id/done_editing"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_marginBottom="#dimen/margin_small"
android:layout_marginTop="#dimen/margin_small"
android:text="Done"
android:textColor="#color/WhiteColor"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</FrameLayout>
</LinearLayout>
<ListView
android:id="#+id/listview1"
android:divider="#android:color/transparent"
android:dividerHeight="0dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
listview row layout where i have to show cross image:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_marginTop="#dimen/margin_large"
android:layout_marginLeft="#dimen/margin_large"
android:layout_marginRight="#dimen/margin_large"
android:background="#drawable/border"
android:padding="#dimen/margin_large"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:weightSum="10"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:text=""
android:layout_gravity="center"
android:layout_weight="9"
android:textColor="#color/TabColor"
android:singleLine="true"
android:textSize="#dimen/text_large"
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<FrameLayout
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:gravity="right"
android:id="#+id/arrow"
android:src="#drawable/rightarrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ImageView
android:visibility="invisible"
android:id="#+id/cross"
android:gravity="right"
android:src="#drawable/cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</FrameLayout>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:weightSum="10"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:text=""
android:layout_weight="5"
android:textColor="#color/blackColor"
android:textSize="#dimen/text_medium"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_weight="5"
android:text=""
android:gravity="right"
android:textColor="#color/blackColor"
android:textSize="#dimen/text_medium"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
Adapter class:
public class MyAdapter extends ArrayAdapter<String> {
private final Context context;
private ArrayList<String> titlelist,datalist;
public MyAdapter(Context context, ArrayList<String> title, ArrayList<String> data) {
super(context, R.layout.listview_row, title);
titlelist= new ArrayList<>();
datalist= new ArrayList<>();
this.context=context;
this.titlelist=title;
this.datalist=data;
}
private static class ViewHolder {
TextView t1,t2;
}
#Override
public int getCount() {
return titlelist.size();
}
#Override
public String getItem(int position) {
return titlelist.get(position);
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
LayoutInflater vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = vi.inflate(R.layout.listview_row, null);
holder = new ViewHolder();
holder.t1 = (TextView) convertView.findViewById(R.id.title);
holder.t2 = (TextView) convertView.findViewById(R.id.data);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.t1.setText(titlelist.get(position));
holder.t2.setText(datalist.get(position));
return convertView;
}
}
you have to add this functionality in your adapter,
#Override
public View getView(int position, View convertView, ViewGroup parent) {
//ur other codes.....
//
//
if(crossButtonPress){
holder.imageView.setImageResource(R.drawable.cross);
}else{
holder.imageView.setImageResource(R.drawable.default_ic);
}
}
In addition, in you actual button's onClick,
crossButtonPress = true;
adapter.notifyDatasetChanged();
<LinearLayout
android:id="#+id/layout_question_detail"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:visibility="gone">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="55dp"
>
<Button
android:id="#+id/btn_question_backButton"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="#drawable/backicon_round"/>
<TextView
android:id="#+id/text_question_detail_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:textColor="#color/color_green"
android:text="Error"
android:textSize="19dp"
/>
</RelativeLayout>
<ImageView
android:id="#+id/image_question_detail_image"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3"
android:scaleType="centerCrop"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:layout_weight="2">
<TextView
android:id="#+id/text_question_detail_userComments"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:layout_marginBottom="25dp"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="3">
<ListView
android:id="#+id/list_question_detail_expComments"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="#android:color/transparent"
android:dividerHeight="10dp"></ListView>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
Now, I set layout for title on the top. Then, a Imageview, a textview and a listview follow below this layout, and only 1 textview is inside listview.
listview can vary in size.
The problem is, if the size of the listview is very big, I can only scroll the screen assigned to listview.
But, I want scroll the entire screen.
To solve this problem, I added scrollview outside of the first linearlayout.
However, It didn't work.(the imageview disappeared)
What can I do?
you can make your listview addheaderview,and put your imageview and textview into headerview
yourlayout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/layout_question_detail"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="55dp">
<Button
android:id="#+id/btn_question_backButton"
android:layout_width="50dp"
android:layout_height="50dp" />
<TextView
android:id="#+id/text_question_detail_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Error"
android:textColor="#000000"
android:textSize="19dp"
/>
</RelativeLayout>
<ListView
android:id="#+id/list_question_detail_expComments"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="#android:color/transparent"
android:dividerHeight="10dp"></ListView>
lv_header.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<ImageView
android:id="#+id/image_question_detail_image"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3"
android:scaleType="centerCrop" />
<TextView
android:id="#+id/text_question_detail_userComments"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="25dp"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:textSize="20dp" />
Activity.class
public class MainActivity extends AppCompatActivity {
private ListView list_question_detail_expComments;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
list_question_detail_expComments = (ListView) findViewById(R.id.list_question_detail_expComments);
View lvHeaderView = View.inflate(this,R.layout.lv_header,null);
list_question_detail_expComments.addHeaderView(lvHeaderView);
list_question_detail_expComments.setAdapter(new LvAdapter());
}
private class LvAdapter extends BaseAdapter{
#Override
public int getCount() {
return 20;
}
#Override
public Object getItem(int i) {
return null;
}
#Override
public long getItemId(int i) {
return 0;
}
#Override
public View getView(int i, View view, ViewGroup viewGroup) {
TextView tv = new TextView(MainActivity.this);
tv.setText("test"+i);
return tv;
}
}
}
I have created a custom ListView with 2 ImageView and a TextView.
In the Adapter, I'm doing setText in TextView, but it is not visible in the app.
Here is my List:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff">
<View
android:layout_width="fill_parent"
android:layout_height="5dp"
android:background="#289FA5"/>
<RelativeLayout
android:layout_marginTop="7dp"
android:layout_marginLeft="7dp"
android:layout_marginBottom="15dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#289FA5">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Popular products"
android:textSize="23sp"
android:padding="7dp"/>
</RelativeLayout>
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="120dp">
<LinearLayout
android:id="#+id/pop_pro_men"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
</LinearLayout>
</HorizontalScrollView>
<RelativeLayout
android:layout_marginTop="15dp"
android:layout_marginLeft="7dp"
android:layout_marginBottom="15dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#289FA5">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Catagories"
android:textSize="23sp"
android:padding="7dp"/>
</RelativeLayout>
<ListView
android:id="#+id/cata_men"
android:layout_width="fill_parent"
android:layout_height="wrap_content"></ListView>
Here is my Custom List:
<LinearLayout
android:id="#+id/custom_list"
android:layout_width="match_parent"
android:layout_height="130dp"
android:layout_marginTop="10dp"
android:orientation="horizontal"
android:background="#ffffff">
<ImageView
android:layout_gravity="left"
android:id="#+id/imageView2"
android:layout_height="130dp"
android:layout_marginLeft="7dp"
android:layout_width="120dp"
android:src="#drawable/clothing_men"/>
<TextView
android:id="#+id/cata_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Clothing"
android:layout_marginTop="35dp"
android:textStyle="bold"
android:textSize="27sp"
android:padding="10dp"
android:layout_weight="1"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/forward_arrow"
android:layout_marginTop="42dp"/>
And Here is the getView method of my Adapter:
public View getView(final int position, View convertView, ViewGroup parent) {
final Holder holder = new Holder();
View rowView;
rowView = inflater.inflate(R.layout.custom_subcatagory_list, null,true);
TextView sub_catagory= (TextView) rowView.findViewById(R.id.cata_name);
ImageView pic = (ImageView) rowView.findViewById(R.id.imageView2);
sub_catagory.setText(catagory[position]);
pic.setImageResource(image[position]);
Log.d("Strings========", sub_catagory.getText().toString());
rowView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(context, "You Clicked " + catagory[position], Toast.LENGTH_LONG).show();
}
});
return rowView;
}
Please Help as i am unable to find what is wrong in this.
Remove your layout_weight attribute from your TextView. If you remove sub_catagory.setText(catagory[position]); does "Clothing" appear when you run your app?
I got the answer now. I don't know how my textColor was set to White, because i didn't mentioned it. So, change the color to something else and it worked.And it wasted my whole day.
Sorry to disturb you all.