I want to achieve drop down and sum up for a View in my ListView Data is being fetched from the database and am using a cursor adapter, I have tried to add onClickListner for the button in onItemClickListner But no Success.
The problem I am facing is When button DROPDOWN is clicked it will make relative layout Visible but when clicked again it won't relative layout visibility to GONE
Heres my Code for CursorAdapter
public class ProductViewCursorAdapter extends CursorAdapter {
private CardView cv_singleItem;
private RelativeLayout infoLayout;
private Button dropDown;
public ProductViewCursorAdapter(Context context, Cursor c) {
super(context, c, 0);
}
#Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
return LayoutInflater.from(context).inflate(R.layout.custom_product_view_listview,parent,false);
}
#Override
public void bindView(View view, Context context, Cursor cursor) {
cv_singleItem = view.findViewById(R.id.cv_custom_single_product);
infoLayout = view.findViewById(R.id.layout_dropdown_relative);
dropDown = view.findViewById(R.id.expand_user_info_listView);
dropDown.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (infoLayout.getVisibility() == View.GONE){
TransitionManager.beginDelayedTransition(cv_singleItem,new AutoTransition());
infoLayout.setVisibility(View.VISIBLE);
dropDown.setBackgroundResource(R.drawable.ic_sumup);
}else{
Log.i("THIS IS TEST","DEMO VIEW "+ infoLayout.getVisibility());
TransitionManager.beginDelayedTransition(cv_singleItem,new AutoTransition());
infoLayout.setVisibility(View.GONE);
dropDown.setBackgroundResource(R.drawable.ic_dropdown);
}
}
});
}
}
ListView single View XML
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.cardview.widget.CardView
android:id="#+id/cv_custom_single_product"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="#style/TextAppearance.AppCompat.Title">
<LinearLayout
android:background="#D5000000"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:id="#+id/image_layout_main"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/iv_product_image_listView"
android:layout_width="match_parent"
android:scaleType="fitCenter"
android:src="#drawable/selimage"
android:layout_height="200dp"/>
<TextView
android:id="#+id/tv_no_image_available"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="No Image Available"
android:textAlignment="center"
android:paddingTop="5dp"
android:textSize="15sp"
android:textStyle="bold|italic"
android:textColor="#color/white"/>
<TextView
android:id="#+id/tv_product_name_listView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Kurti"
android:textSize="18sp"
android:textColor="#FFFFFF"
android:fontFamily="sans-serif-black"
android:textStyle="italic"
android:layout_marginLeft="20dp"
android:layout_below="#id/iv_product_image_listView"
android:layout_marginTop="-25dp"/>
<Button
android:id="#+id/expand_user_info_listView"
android:layout_alignParentEnd="true"
android:layout_below="#id/iv_product_image_listView"
android:focusable="false"
android:layout_marginTop="-49dp"
android:layout_marginEnd="8dp"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="#drawable/ic_dropdown"/>
</RelativeLayout>
<RelativeLayout
android:id="#+id/layout_dropdown_relative"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:layout_marginStart="15dp"
android:layout_marginEnd="15dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp">
<TextView
android:id="#+id/tv_date_dropdown_listView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2020-12-14"
android:textAppearance="?android:textAppearanceMedium"
android:textColor="#E2FFFFFF"
android:fontFamily="sans-serif-condensed"
android:textStyle="bold"
android:layout_marginStart="4dp"/>
<TextView
android:id="#+id/tv_profit_dropdown_listView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Profit 500"
android:textAppearance="?android:textAppearanceMedium"
android:textColor="#E2FFFFFF"
android:fontFamily="sans-serif-condensed"
android:textStyle="bold"
android:layout_marginStart="4dp"
android:layout_alignParentEnd="true"/>
<TextView
android:id="#+id/tv_sellingPrice_dropdown_listView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Selling Price: 800"
android:textAppearance="?android:textAppearanceMedium"
android:textColor="#E2FFFFFF"
android:fontFamily="sans-serif-condensed"
android:textStyle="bold"
android:layout_marginStart="4dp"
android:layout_below="#id/tv_date_dropdown_listView"
android:paddingTop="3dp"/>
<TextView
android:id="#+id/tv_actualPrice_dropDown_listView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Actual Price: 850"
android:textAppearance="?android:textAppearanceMedium"
android:textColor="#E2FFFFFF"
android:fontFamily="sans-serif-condensed"
android:textStyle="bold"
android:layout_marginStart="4dp"
android:layout_alignParentRight="true"
android:layout_below="#id/tv_profit_dropdown_listView"
android:paddingTop="3dp"/>
<TextView
android:id="#+id/tv_pending_dropdown_listView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pending: 0"
android:textAppearance="?android:textAppearanceMedium"
android:textColor="#F50057"
android:fontFamily="sans-serif-condensed"
android:textStyle="bold"
android:layout_marginStart="4dp"
android:layout_below="#id/tv_sellingPrice_dropdown_listView"
android:paddingTop="3dp"/>
<Button
android:id="#+id/btn_update_single_item"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_below="#id/tv_actualPrice_dropDown_listView"
android:layout_alignParentEnd="true"
android:background="#drawable/ic_update"/>
</RelativeLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
</RelativeLayout>
You are using the same infoLayout for every list view row. Every time bindView() gets called you replace the infoLayout with new layout. This of course causes the problem that when you use infoLayout.setVisibility(View.VISIBLE); the infoLayout it's not the same layout it was when the list view row was created because you have replaced it.
So replace,
infoLayout = view.findViewById(R.id.layout_dropdown_relative);
with
final RelativeLayout infoLayout = view.findViewById(R.id.layout_dropdown_relative);
Related
I have 2 TextViews showing on the main UI. I associate each TextView to a unique clickListener that launches a unique AlertDialog for the user to make a selection. The first TextView is launching the second layout for the second AlertDialog rather than the expected first layout for the first AlertDialog. What am I missing here?
activity_main.xml file
...
<TextView
android:id="#+id/fList"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="20dp"
android:layout_marginStart="20dp"
android:text="filter"
android:textStyle="bold|italic"
android:textColor="#color/text_primary"
/>
<TextView
android:id="#+id/qList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="quickList"
android:textStyle="bold"
android:textColor="#color/text_primary"
android:gravity="center"
/>
MainActivity.java file
public class MainActivity extends AppCompatActivity
...
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView mTextViewFilter = (TextView)findViewById(R.id.fList);
TextView mTextViewQuickList = (TextView)findViewById(R.id.qList);
mTextViewFilter.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view){
final AlertDialog.Builder alertDialogFilter = new AlertDialog.Builder(MainActivity.this);
LayoutInflater inflaterFilter = getLayoutInflater();
final ViewGroup nullParent = null;
// the AlertDialog layout for the first TextView click.
final View dialogLayoutFilter = inflaterFilter.inflate(R.layout.filter_main, nullParent);
alertDialogFilter.setView(dialogLayoutFilter);
final AlertDialog dialogFilter = alertDialogFilter.show();
...
}
});
mTextViewQuickList.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
final AlertDialog.Builder alertDialog = new AlertDialog.Builder(MainActivity.this);
LayoutInflater inflater = getLayoutInflater();
final ViewGroup nullParent = null;
// the AlertDialog layout for the second TextView click.
final View dialogLayout = inflater.inflate(R.layout.entire_layout, nullParent);
alertDialog.setView(dialogLayout);
final AlertDialog dialog = alertDialog.show();
...
}
});
entire_layout.xml
...
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minWidth="380dp"
android:minHeight="160dp" >
<ImageView
android:id="#+id/imageViewX"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:paddingRight="20dp"
android:paddingEnd="20dp"
android:contentDescription="x"
android:src="#drawable/ic_close_white_24dp" />
<TextView
android:id="#+id/FullList"
android:layout_below="#+id/imageViewX"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginStart="20dp"
android:layout_marginLeft="20dp"
android:textStyle="bold"
android:textAppearance="#android:style/TextAppearance.Large"
android:text="Show entire list" />
<TextView
android:id="#+id/fullNewest"
android:layout_below="#+id/FullList"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginStart="40dp"
android:layout_marginLeft="40dp"
android:layout_marginBottom="10dp"
android:textAppearance="#android:style/TextAppearance.Medium"
android:text="Created ... />
filter_main.xml
...
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minWidth="380dp"
android:minHeight="280dp" >
<ImageView
android:id="#+id/imageViewX"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:paddingRight="20dp"
android:paddingEnd="20dp"
android:contentDescription="x"
android:src="#drawable/ic_close_white_24dp" />
<TextView
android:id="#+id/Filter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/imageViewX"
android:layout_marginStart="20dp"
android:layout_marginLeft="20dp"
android:textStyle="bold"
android:textAppearance="#android:style/TextAppearance.Large"
android:text="Filter..." />
<TextView
android:id="#+id/AllDos"
android:layout_below="#+id/Filter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginStart="40dp"
android:layout_marginLeft="40dp"
android:textAppearance="#android:style/TextAppearance.Medium"
android:text="All..." />
<TextView
android:id="#+id/AllBuys"
android:layout_below="#+id/AllDos"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginStart="40dp"
android:layout_marginLeft="40dp"
android:textAppearance="#android:style/TextAppearance.Medium"
android:text="All..." />
<TextView
android:id="#+id/AllWork"
android:layout_below="#+id/AllBuys"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginStart="40dp"
android:layout_marginLeft="40dp"
android:textAppearance="#android:style/TextAppearance.Medium"
android:text="All..." />
<TextView
android:id="#+id/AllHome"
android:layout_below="#+id/AllWork"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginStart="40dp"
android:layout_marginLeft="40dp"
android:textAppearance="#android:style/TextAppearance.Medium"
android:text="All..." />
<TextView
android:id="#+id/AllWaitingfor"
android:layout_below="#+id/AllHome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginStart="40dp"
android:layout_marginLeft="40dp"
android:layout_marginBottom="5dp"
android:textAppearance="#android:style/TextAppearance.Medium"
android:text="All..." />
Not sure what your textviews' parent is but since you are using attributes like:
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
I guess it is a RelativeLayout.
Since you aren't using neither an orientation nor a relative position, I suppose your TextViews are both on the same line, with just a different margin top, but the quick list TextView has width match_parent and gravity center
android:layout_width="match_parent"
android:gravity="center"
So what's happening is something like this:
And your click always triggers the second TextView that covers entirely the first one.
To fix it change your quick list TextView this way:
<TextView
android:id="#+id/qList"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="quickList"
android:textStyle="bold"
android:textColor="#color/text_primary"
android:layout_centerHorizontal="true"/>
With the attributes:
android:layout_width="wrap_content"
android:layout_centerHorizontal="true"
It will be centered but not overlapping the first TextView.
I hope this could help, if instead I am wrong and your activity_main.xml file differs, please update your code so that it can be easier figure out any alternative problem.
This is the getChildView inside the Adapter class...
public View getChildView(int parent, int child, boolean lastChild, View view, ViewGroup viewGroup) {
ArrayList<String> itemDetails= (ArrayList<String>)getChild(parent,child);
if(view==null)
{
LayoutInflater inflater= (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view= inflater.inflate(R.layout.child_layout,viewGroup,false);
}
TextView textView =(TextView)view.findViewById(R.id.textView2);
textView.setText(itemDetails.get(0));
TextView textView1(TextView)view.findViewById(R.id.itemdescription);
textView1.setText(itemDetails.get(1));
TextView textView3= (TextView)view.findViewById(R.id.price);
textView3.setText(itemDetails.get(2));
final TextView textView2 = (TextView)view.findViewById(R.id.counterTextView);
ImageButton add = (ImageButton)view.findViewById(R.id.imageButton);
final ImageButton remove = (ImageButton)view.findViewById(R.id.imageButton1);
add.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
textView2.setText(String.valueOf(Integer.parseInt(textView2.getText().toString())+1));
remove.setVisibility(View.VISIBLE);
}
});
remove.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if(Integer.parseInt(textView2.getText().toString())==0)
{
remove.setVisibility(View.INVISIBLE);
}
else {
textView2.setText(String.valueOf(Integer.parseInt(textView2.getText().toString()) - 1));
}
}
});
return view;
}
This is the ChildLayout:
<?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:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="5dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="5dp"
android:background="#FFFFFF">
<ImageView
android:layout_width="match_parent"
android:layout_height="150dp"
android:scaleType="centerCrop"
app:srcCompat="#drawable/k_meals_rs"
android:id="#+id/imageView6" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:textSize="20sp"
android:textColor="#000000"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:paddingRight="10dp">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#drawable/ic_remove_black"
android:id="#+id/imageButton1"
android:background="#drawable/round_button"
android:visibility="invisible"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:gravity="center_vertical"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:textColor="#000000"
android:id="#+id/counterTextView" />
<ImageButton
app:srcCompat="#drawable/ic_add_black"
android:id="#+id/imageButton"
android:background="#drawable/round_button"
android:layout_width="29dp"
android:layout_height="29dp" />
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingRight="10dp">
<TextView
android:id="#+id/itemdescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:maxEms="15"
android:textColor="#000000"/>
<TextView
android:id="#+id/price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="₹150"
android:textColor="#000000"/>
</RelativeLayout>
</LinearLayout>
i want to increment & decrements the value of counterTextView as the the + and - buttons are pressed.. but as i do so it increment and decrements the value of counterTextView in other child in other parents with same index value...any idea how to overcome this problem.. thnx
this is my adapter, the getView method is not called even if the array list having elements
public class CarrierSammuryAdapter extends ArrayAdapter<CarrierSummary> {
private final Activity context;
private final ArrayList<CarrierSummary> ite;
private final int lay;
public CarrierSammuryAdapter(Activity context, ArrayList<CarrierSummary> menuLinkList,int layout) {
super(context,layout );
this.context = context;
this.ite = menuLinkList;
this.lay=layout;
}
// static to save the reference to the outer class and to avoid access to
// any members of the containing class
static class ViewHolder {
public TextView customer;
public TextView attempts;
public TextView successful;
public TextView minutes;
public TextView ASR;
public TextView ACD;
public TextView NER;
public TextView PDD;
}
#Override
public int getCount () {
return ite.size();
}
#Override
public long getItemId (int position) {
return position;
}
#Override
public CarrierSummary getItem (int position) {
return ite.get(position);
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
// ViewHolder will buffer the assess to the individual fields of the row layout
final ViewHolder holder;
// Recycle existing view if passed as parameter
// This will save memory and time on Android
// This only works if the base layout for all classes are the same
View rowView = convertView;
if (rowView == null) {
LayoutInflater inflater = context.getLayoutInflater();//this gives error !!
rowView=inflater.inflate(R.layout.carriersumamry_item,parent,false);
holder = new ViewHolder();
holder.customer=(TextView)rowView.findViewById(R.id.customer);
holder.attempts=(TextView)rowView.findViewById(R.id.attempts);
holder.successful=(TextView)rowView.findViewById(R.id.successful);
holder.minutes=(TextView)rowView.findViewById(R.id.minutes);
holder.ASR=(TextView)rowView.findViewById(R.id.asr);
holder.ACD=(TextView)rowView.findViewById(R.id.acd);
holder.NER=(TextView)rowView.findViewById(R.id.ner);
holder.PDD=(TextView)rowView.findViewById(R.id.pdd);
// ViewResizing.setListRowTextResizing(rowView, context);
rowView.setTag(holder);
} else {
holder = (ViewHolder) rowView.getTag();
}
holder.customer.setText(ite.get(position).getCustomer());
holder.attempts.setText(ite.get(position).getAttempts());
holder.successful.setText(ite.get(position).getSuccessful());
holder.minutes.setText(ite.get(position).getMinutes());
holder.ASR.setText(ite.get(position).getASR());
holder.ACD.setText(ite.get(position).getACD());
holder.NER.setText(ite.get(position).getNER());
holder.PDD.setText(ite.get(position).getPDD());
return rowView;
}
}
and this is how i called it
carrierSummaryList =(ListView)findViewById(R.id.carrierSummary_listview);
CarrierSammuryAdapter adapter = new CarrierSammuryAdapter(CarrierSummaryActivity.this, carriersam,R.layout.carriersumamry_item);
carrierSummaryList.setAdapter(adapter);
I search a lot to solve this issue but no solution, getView method is never called.
this is my XML
<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="horizontal"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/pdd"
android:textColor="#color/grey"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/ner"
android:textColor="#color/grey"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/acd"
android:textColor="#color/grey"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/asr"
android:textColor="#color/grey"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/minutes"
android:textColor="#color/grey"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/successful"
android:textColor="#color/grey"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/attempts"
android:textColor="#color/grey"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/customer"
android:textColor="#color/grey"
/>
</LinearLayout>
I had this exact same problem, to solve it, I simply changed the ArrayAdapter to BaseAdapter, implemented the overriden methods and it worked.
And as khuskal said, you should always use Context instead of Activity.
there are two mistakes..
first is change Activity to Contex in constructor
secondly change
rowView=inflater.inflate(R.layout.single_row,parent,false);
Hope this will help you
/**
* Constructor
*
* #param context The current context.
* #param resource The resource ID for a layout file containing a TextView to use when
* instantiating views.
*/
public ArrayAdapter(Context context, int resource) {
init(context, resource, 0, new ArrayList<T>());
}
while you are doing super(context,layout) , this is the constructor that gets called. So adapter data is set to empty list.
Like derek said, Instead you should use super(context,layout,menuLinkList);
/**
* Constructor
*
* #param context The current context.
* #param resource The resource ID for a layout file containing a TextView to use when
* instantiating views.
* #param objects The objects to represent in the ListView.
*/
public ArrayAdapter(Context context, int resource, List<T> objects) {
init(context, resource, 0, objects);
}
The problem was in my drawerLayout, i put the listView into RelativeLayout but when i change to LinearLayout its working, this is the code
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#android:color/white"
android:orientation="vertical">
<include
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/mainbar"
layout="#layout/second_topmain"/>
<ListView
android:id="#+id/carrierSummary_listview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#android:color/black"
></ListView>
<include
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginBottom="0dp"
android:id="#+id/mainbar"
layout="#layout/bottom_bar"/>
</LinearLayout>
<LinearLayout
android:id="#+id/linearSlider"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="right"
android:background="#7e7e7e"
android:orientation ="vertical">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Carrier Type"
android:textColor="#android:color/white"
android:padding="5dp"
android:background="#color/darkgrey"
/>
<LinearLayout
android:padding="3dp"
android:layout_width="wrap_content"
android:orientation="horizontal"
android:background="#color/darkgrey"
android:layout_height="wrap_content">
<Button
android:id="#+id/customerButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/grey"
android:onClick="toggleClicked"
android:background="#drawable/toggleon"
android:text="Customer"
/>
<Button
android:id="#+id/SupplierButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="toggleClicked"
android:textColor="#color/grey"
android:background="#drawable/toggleoff"
android:text="Supplier"
/>
</LinearLayout>
<RelativeLayout
android:padding="3dp"
android:layout_width="wrap_content"
android:orientation="horizontal"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Carrier"
android:layout_alignParentLeft="true"
android:layout_centerHorizontal="true"
/>
<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/spinnerCarrier"
android:layout_alignParentRight="true"
android:background="#android:color/transparent"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
<RelativeLayout
android:padding="3dp"
android:background="#color/darkgrey"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Top"
android:layout_alignParentLeft="true"
android:layout_centerHorizontal="true"
/>
<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/SpinnerTop"
android:layout_alignParentRight="true"
android:background="#android:color/transparent"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
<RelativeLayout
android:padding="3dp"
android:layout_width="wrap_content"
android:onClick="showDateTimePickerFrom"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="From Date"
android:layout_alignParentLeft="true"
android:layout_centerHorizontal="true"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/fromDate"
android:layout_alignParentRight="true"
android:background="#android:color/transparent"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
<RelativeLayout
android:padding="3dp"
android:background="#color/darkgrey"
android:layout_width="wrap_content"
android:onClick="showDateTimePickeTo"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="To Date"
android:layout_alignParentLeft="true"
android:layout_centerHorizontal="true"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/toDate"
android:layout_alignParentRight="true"
android:background="#android:color/transparent"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
<RelativeLayout
android:padding="3dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Group By Profile"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/byprofilecheck"
android:layout_alignParentRight="true"
android:background="#android:color/transparent"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
This is custom View layout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="25dp"
android:background="#drawable/newbackrow"
android:clickable="true"
android:orientation="vertical" >
<TextView
android:id="#+id/txt_search_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="15dp"
android:layout_toLeftOf="#+id/txt_search_sport"
android:layout_weight="1"
android:focusable="false"
android:inputType="textMultiLine"
android:maxLines="2"
android:singleLine="false"
android:text="TextView"
android:textColor="#android:color/white"
android:textSize="13dp"
android:textStyle="bold" />
<TextView
android:id="#+id/txt_search_sport"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:focusable="false"
android:layout_marginLeft="10dp"
android:background="#color/red"
android:padding="0dp"
android:text="TextView"
android:textColor="#android:color/white"
android:textSize="10dp"
android:textStyle="bold" />
</RelativeLayout>
// layour inflate in getview() methode
view perfectly dispay but its not clickable ,let me suggest where going to wrong or any other
** // autocompletetextview OnItemclicklistener**
search_text.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adapter, View myView, int position,
long arg3) {
Toast.makeText(getApplicationContext(), "Position = "+position, Toast.LENGTH_LONG).show();
}
}
I have an activity with a ListView. ListView with custom views. I add OnItemClickLIstener to the ListView. and when i click on item, in result i see nothing.
Activity with ListView:
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#color/silver_conv">
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="40dp" android:layout_alignParentTop="true" android:id="#+id/topcontainer"
android:background="#color/black">
</FrameLayout>
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/chat_list" android:layout_below="#+id/topcontainer"
android:layout_above="#+id/last_action"
android:cacheColorHint="#00000000"
android:layout_marginRight="2dp" android:clickable="true"/>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="last action was at time" android:id="#+id/last_action"
android:longClickable="false"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="false" android:layout_above="#+id/action_container"
android:layout_marginBottom="5dp" android:layout_alignParentLeft="false" android:layout_marginLeft="5dp"/>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="43dp" android:layout_alignParentBottom="true" android:id="#+id/action_container"
android:background="#drawable/conv_botom_action_gradient">
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="#string/send"
android:id="#+id/send_message_btn" android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:background="#drawable/blue_button_selector" android:textColor="#color/white"
android:layout_marginLeft="3dp" android:layout_marginTop="3dp"/>
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="#+id/add_attach_btn"
android:layout_alignParentLeft="true" android:layout_alignParentBottom="true"
android:background="#drawable/add_attach_button_selector"
android:layout_marginRight="2dp" android:layout_marginBottom="3dp" android:layout_marginTop="3dp"/>
<EditText android:layout_width="40dp" android:layout_height="wrap_content" android:id="#+id/message_et"
android:layout_toRightOf="#+id/add_attach_btn" android:layout_toLeftOf="#+id/send_message_btn"
android:singleLine="true" android:layout_alignParentBottom="true" android:hint="Type message here"
android:background="#drawable/message_input" android:layout_marginBottom="3dp"
android:gravity="center_vertical" android:layout_marginTop="3dp"/>
</RelativeLayout>
View item:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:gravity="center_vertical|left" android:focusable="false">
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:background="#drawable/incoming_message"
android:id="#+id/container" android:layout_marginTop="5dp" android:layout_marginBottom="5dp"
android:focusable="false">
<FrameLayout android:layout_width="wrap_content" android:layout_height="wrap_content"
android:focusableInTouchMode="true" android:id="#+id/attach_container" android:focusable="false"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="saa"
android:id="#+id/message_text" android:textSize="17sp" android:textColor="#color/black"
android:focusable="false"/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:id="#+id/date" android:textColor="#color/black" android:singleLine="true" android:lines="1"
android:maxLines="1" android:ellipsize="none" android:layout_marginLeft="5dp" android:focusable="false"/>
And finally clickListener:
private AdapterView.OnItemClickListener clickLister = new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int pos, long l) {
try {
LinearLayout container = (LinearLayout)view.findViewById(R.id.container);
TextView message = (TextView)container.findViewById(R.id.message_text);
message.setTextColor(mContext.getResources().getColor(R.color.white));
Log.e("My item is", "" + pos);
}catch (Exception e){
e.printStackTrace();
}
}
};
And here is Initialization of ListView:
mConvListView = (ListView)findViewById(R.id.chat_list);
mConvListView.setDivider(null);
mConvListView.setDividerHeight(0);
mConvListView.setItemsCanFocus(false);
mConvListView.setOnItemClickListener(clickLister);
mConvListView.setTranscriptMode(ListView.TRANSCRIPT_MODE_ALWAYS_SCROLL);
mConvListView.setStackFromBottom(true);
P.s. Sorry for a lot code. But I can't find any suggestion a second day.
By setting focusable objects in your row layout, you are preventing the ListView from getting the touch event.
This FrameLayout is consuming the touch event:
<FrameLayout
android:id="#+id/attach_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusableInTouchMode="true"
android:focusable="false"/>
Remove the focusable settings so it looks like this:
<FrameLayout
android:id="#+id/attach_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
(You really should organize your XML so that is is readable, in Eclipse use Ctrl+Shift+F.)
Make Focus for all components as follows :
android:focusable="false"
android:focusableInTouchMode="false"
I guess you are not getting the item the right way. Try this:
int position = (int) adapterView.getSelectedItemId();
Log.i("Position:", Integer.toString(position));
Edit
Try this piece of code.
ListView lv = (ListView)findViewById(R.id.chat_list);
lv.setOnItemClickListener(new OnItemClickListener(){
#Override
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
int position = (int) parent.getSelectedItemId();
Log.i("Position:", Integer.toString(position));
}
});