I have made an app that has a list of insurance companies using a listView. The listView is populated using an array adapter. I want to be able to search through this list with a search bar and only return an insurance company that is searched for. I have fallowed a tutorial however it doesn't filter the insurance companies. Can someone tell me where I'm going wrong
Here is my code so far
insurance.xml
<EditText
android:layout_width="400dp"
android:layout_height="60dp"
android:id="#+id/editText"
android:layout_marginBottom="50dp"
/>
<ListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="107dp">
</ListView>
myList.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="match_parent"
android:orientation="horizontal"
android:layout_weight="10"
android:background="#26BFDA">
<LinearLayout
android:layout_width="0dp"
android:layout_height="60dp"
android:layout_weight="2"
>
<ImageView
android:id="#+id/icon"
android:layout_width="60dp"
android:layout_height="60dp"
android:padding="5dp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="6"
android:orientation="vertical"
>
<TextView
android:id="#+id/item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:padding="2dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#FFFFFF"
/>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="TextView"
/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:orientation="vertical"
>
<ImageView
android:id="#+id/imageView2"
android:layout_width="20dp"
android:layout_height="50dp"
android:layout_alignParentRight="true"
android:src="#drawable/nextarrow"
/>
</LinearLayout>
</LinearLayout>
Insurance.java
public class Insurance extends AppCompatActivity {
ListView list;
ArrayAdapter<String> newadapter;
EditText inputSearch;
String[] itemname ={
"AA",
"Acorn",
"Admiral",
};
Integer[] imgid= {
R.drawable.aa,
R.drawable.acorn,
R.drawable.admiral,
};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_insurance);
CustomListAdapter adapter=new CustomListAdapter(this, itemname, imgid);
list=(ListView)findViewById(R.id.list);
newadapter = new ArrayAdapter<String>(this, R.layout.mylist, R.id.item, itemname);
inputSearch = (EditText) findViewById(R.id.editText);
list.setAdapter(newadapter);
inputSearch.addTextChangedListener(new TextWatcher() {
#Override
public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
// When user changed the Text
Insurance.this.newadapter.getFilter().filter(cs);
}
#Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
// TODO Auto-generated method stub
}
#Override
public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub
}
});
list.setAdapter(adapter);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// TODO Auto-generated method stub
String Slecteditem = itemname[+position];
Toast.makeText(getApplicationContext(), Slecteditem, Toast.LENGTH_SHORT).show();
if (Slecteditem.toString() == "AA") {
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:028 9032 2232"));
startActivity(intent);
}
if (Slecteditem.toString() == "Carrot") {
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:028 9032 2265"));
startActivity(intent);
}
}
});
Related
Please help Me,
I am trying to create a specific type of recycler view which can have always 3 items in all kind of mobile phone. Whether that mobile is having 4 inch display or 6.5 inch display.
Please tell me if that is possible or not.
my code of xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="100dp"
android:id="#+id/recomended"
android:layout_margin="6dp"
android:background="#drawable/graycurverdbtn"
android:layout_height="170dp">
<ImageView
android:id="#+id/image"
android:layout_width="match_parent"
android:layout_height="85dp"
android:scaleType="fitCenter"
android:src="#drawable/mountain">
</ImageView>
<LinearLayout
android:layout_width="match_parent"
android:layout_margin="10dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="15dp"
android:gravity="center"
>
<TextView
android:id="#+id/pinkbtn"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="#drawable/pinkcurvedbtn"
android:gravity="center"
android:padding="3dp"
android:text="Recomended"
android:textColor="#color/white"
android:textSize="9dp">
</TextView>
</LinearLayout>
<LinearLayout
android:layout_below="#id/image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_margin="8dp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="normal"
android:layout_margin="6dp"
android:layout_gravity="center"
android:textSize="10sp"
android:textColor="#color/black"
android:text="Pest control">
</TextView>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/grey"></View>
<TextView
android:layout_margin="8dp"
android:id="#+id/shopname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="10dp"
android:textStyle="bold"
android:textColor="#color/black"
android:text="K02BgbhdAf">
</TextView>
<TextView
android:visibility="gone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/graylocation"
android:text="Airport Road"
android:id="#+id/address"
android:textSize="18sp"
android:textStyle="normal">
</TextView>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
This is my Adapter code
public class OurrecomendedAdapter extends RecyclerView.Adapter<OurrecomendedAdapter.MyViewHolder> {
private List<HomeResponse.Recommend> ourrecomendedlist = new ArrayList<>();
private Context context;
public static int recomendedid=0;
public OurrecomendedAdapter(List<HomeResponse.Recommend> list, Context context) {
this.ourrecomendedlist = list;
this.context = context;
}
#Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.recomemdedservices_item, parent, false);
// itemView.setLayoutParams(new ViewGroup.LayoutParams((int) (parent.getWidth() * 0.3),ViewGroup.LayoutParams.MATCH_PARENT));
return new MyViewHolder(itemView);
}
#Override
public void onBindViewHolder(MyViewHolder holder, #SuppressLint("RecyclerView") int position) {
holder.title.setText(ourrecomendedlist.get(position).getCategory().getSlug());
holder.shopname.setText(ourrecomendedlist.get(position).getCategory().getName());
Picasso.get().load(ourrecomendedlist.get(position).getImage()).into(holder.image, new Callback() {
#Override
public void onSuccess() {
}
#Override
public void onError(Exception e) {
}
});
holder.recomended.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(ourrecomendedlist.get(position).getCategory().getName().toString().equalsIgnoreCase("salon for women") || ourrecomendedlist.get(position).getCategory().getName().toString().equalsIgnoreCase("salon for men")){
AppCompatActivity activity = (AppCompatActivity) context;
WomensalonlistFragment subc = new WomensalonlistFragment();
Bundle args = new Bundle();
args.putString("id", ourrecomendedlist.get(position).getProductcategoryId().toString());
args.putString("title", ourrecomendedlist.get(position).getName());
subc.setArguments(args);
activity.getSupportFragmentManager().beginTransaction().addToBackStack(null).
replace(R.id.nav_host_fragment, subc).commit();
}
else
{
typeListid= ourrecomendedlist.get(position).getId().toString();
Intent intent= new Intent(context, ProductdetailsActivity.class);
intent.putExtra("productId",typeListid);
context.startActivity(intent);
HomeFragment.vendormainid=ourrecomendedlist.get(position).getId().toString();
}
}
});
}
#Override
public int getItemCount() {
return this.ourrecomendedlist.size();
}
class MyViewHolder extends RecyclerView.ViewHolder {
TextView name,title,shopname,address,pinkbtn;
Button addtocart;
ImageView image;
RelativeLayout recomended;
MyViewHolder(View itemView) {
super(itemView);
addtocart=itemView.findViewById(R.id.addtocart);
image=itemView.findViewById(R.id.image);
title=itemView.findViewById(R.id.title);
shopname=itemView.findViewById(R.id.shopname);
address=itemView.findViewById(R.id.address);
recomended=itemView.findViewById(R.id.recomended);
name=itemView.findViewById(R.id.name);
pinkbtn=itemView.findViewById(R.id.pinkbtn);
}
}
}
in this i need to display our output as 3 items in each aspect-ratio mobile.
but I'm unable to achieve that. If I'm opening in big screen mobile then it's showing 3.5 items and in small device some times it's showing 2.75 items.
Kindly help me in that how to achieve that exact output.
I've used SwipeDeck2, I set every thing and it is working, but I have one issue that is I can not set OnClickListener correctly on one of the views in card I have layout as
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/root_cv"
style="#style/CardViewStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="24dp"
android:elevation="5dp"
app:cardCornerRadius="7dp"
android:layout_gravity="top">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<org.team.asl.me_c.ui.DynamicHeightImageView
android:id="#+id/iv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="88dp"
android:scaleType="fitCenter"
app:heightRatio="1.0"
android:background="#color/grey_white_1000"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:orientation="vertical"
android:gravity="center_vertical"
android:padding="16dp"
android:background="#color/indigo_A200"
android:layout_gravity="bottom">
<TextView android:layout_marginTop="-15dp"
android:id="#+id/display_name_tv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#android:color/white"
android:fontFamily="sans-serif"
android:textStyle="bold"
android:textSize="22sp"/>
<TextView
android:id="#+id/username_tv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#android:color/white"
android:fontFamily="sans-serif"
android:textSize="16sp"/>
</LinearLayout>
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipChildren="true">
<ImageButton
android:id="#+id/btnLike"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_gravity="top|right"
android:background="#android:color/transparent"
android:src="#drawable/ic_heart_outline_grey" />
<TextView
android:id="#+id/like_tv"
android:layout_width="120dp"
android:background="#drawable/shape_bg_green_rounded_rect"
android:layout_height="56dp"
android:gravity="center"
android:textSize="32sp"
android:text="LIKE"
android:textStyle="bold"
android:alpha="0"
android:layout_marginTop="32dp"
android:layout_marginBottom="32dp"
android:layout_marginLeft="24dp"
android:textColor="#android:color/holo_green_light"/>
<TextView
android:id="#+id/nope_tv"
android:layout_gravity="right"
android:layout_width="120dp"
android:background="#drawable/shape_bg_red_rounded_rect"
android:layout_height="56dp"
android:textSize="32sp"
android:gravity="center"
android:textStyle="bold"
android:text="NOPE"
android:alpha="0"
android:layout_marginTop="32dp"
android:layout_marginBottom="32dp"
android:layout_marginRight="24dp"
android:textColor="#android:color/holo_red_light"/>
</FrameLayout>
</FrameLayout>
</android.support.v7.widget.CardView>
and the adapter as
public class SwipeDeckAdapter extends BaseAdapter {
private List<String> data;
private Context context;
private int countLike = 0;
private ImageButton btnLike;
//private View.OnClickListener onClickListener;
public SwipeDeckAdapter(List<String> data, Context context) {
this.data = data;
this.context = context;
}
#Override
public int getCount() {
return data.size();
}
#Override
public Object getItem(int position) {
return data.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
View v = convertView;
if(v == null){
LayoutInflater inflater = LayoutInflater.from(context);
// normally use a viewholder
v = inflater.inflate(R.layout.product_card, parent, false);
}
((TextView) v.findViewById(R.id.display_name_tv)).setText(data.get(position));
btnLike = (ImageButton) v.findViewById(R.id.btnLike);
v.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String item = (String)getItem(position);
Log.e("MainActivity", item);
}
});
btnLike.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
countLike ++;
Log.e("LIKE_CONT", " is " + countLike);
btnLike.setImageDrawable(context.getResources().getDrawable(R.drawable.ic_heart_red));
Toast.makeText(context, "Clicked at index ", Toast.LENGTH_SHORT).show();
}
});
return v;
}
}
I want to add click listener on btnLike and want to change the image resource in method
btnLike.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
countLike ++;
Log.e("LIKE_CONT", " is " + countLike);
btnLike.setImageDrawable(context.getResources().getDrawable(R.drawable.ic_heart_red));
Toast.makeText(context, "Clicked at index ", Toast.LENGTH_SHORT).show();
}
});
but result is
means the image resource of btnLike is not changed in current card but as I shuffle cards and see on the other card the image resource of btnLike is changed any suggestions how to see that bit of code so that it can work properly...
I was tried to implement the spinner inside the popupwindow, selection of spinner item with OnItemselection was not working, I have two kind of Experimental Test in this scenario.
Experimental Test-1 I've implemented the OnItemSelectionListener,result of experiment test-1 is
java.lang.NullPointerException: Attempt to invoke virtual method 'void
android.widget.Button.setOnClickListener(android.view.View$OnClickListener)'
on a null object reference.
Experimental Test-2 use getSelectedItem() method to get the position, result of only first position value showing in Toast.
Here is my code,
Java Code Implementation
private void DialogTest(){
String[] Title = {"Select Title","Teacher","Employer","Lecturer","Coach","Mentor","Co-Worker","Prinicpal","Dean","Other"};
LayoutInflater layoutInflater =(LayoutInflater)getActivity().getBaseContext().getSystemService(getActivity().LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.dialog_test, null);
final PopupWindow popupWindow = new PopupWindow(popupView, isPortrait ? getHeightByPercentage(50) : getWidthByPercentage(50), LinearLayout.LayoutParams.WRAP_CONTENT);
Spinner popupSpinner = (Spinner)popupView.findViewById(R.id.popupspinner);
Button button_test_cancel =(Button)popupView.findViewById(R.id.button_test_cancel);
Button button_test_send =(Button)popupView.findViewById(R.id.button_test_send);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item, Title);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
popupSpinner.setAdapter(adapter);
popupWindow.showAsDropDown(btn_request_testimonial, 50, -30);
//Step-1 Experimental Test
popupSpinner.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
int selectedPosition = position;
Toast.makeText(getActivity().getBaseContext(),selectedPosition, Toast.LENGTH_LONG).show();
}
});
//Step-2 Experimental Test
final String categoryTitle = popupSpinner.getSelectedItem().toString();
Toast.makeText(getActivity().getBaseContext(),categoryTitle, Toast.LENGTH_LONG).show();
button_test_send.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
}
});
button_test_cancel.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
popupWindow.dismiss();
}
});
popupWindow.setOutsideTouchable(true);
popupWindow.setFocusable(true);
}
dialog_test.xml
<?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="match_parent"
android:background="#color/white"
android:orientation="vertical">
<RelativeLayout android:layout_width="match_parent"
android:layout_height="38dp"
android:background="#color/colorAccent">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/testimonial_request"
android:textSize="14sp"
android:textStyle="bold"
android:textColor="#color/white"
android:layout_centerInParent="true"/>
</RelativeLayout>
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp">
<EditText
android:id="#+id/edTxt_Testi_Name"
style="#style/edittextstyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Name"
android:inputType="textPersonName"
android:textColor="#color/colorPrimaryDark"
android:textColorHint="#color/colorAccent"
tools:ignore="HardcodedText"/>
<!--android:text="Trd#sm20"-->
</android.support.design.widget.TextInputLayout>
<Spinner
android:id="#+id/popupspinner"
style="#style/edittextstyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:spinnerMode="dialog"
android:textColor="#color/colorPrimaryDark"
android:textColorHint="#color/colorAccent"/>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp">
<EditText
android:id="#+id/edTxt_Testi_Email"
style="#style/edittextstyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="E-Mail"
android:inputType="textEmailAddress"
android:textColor="#color/colorPrimaryDark"
android:textColorHint="#color/colorAccent"
tools:ignore="HardcodedText"/>
<!--android:text="Trd#sm20"-->
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp">
<EditText
android:id="#+id/edTxt_Testi_Org"
style="#style/edittextstyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Organization Name"
android:inputType="textPersonName"
android:textColor="#color/colorPrimaryDark"
android:textColorHint="#color/colorAccent"
tools:ignore="HardcodedText"/>
<!--android:text="Trd#sm20"-->
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp">
<EditText
android:id="#+id/edTxt_Testi_Comments"
style="#style/edittextstyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Comments"
android:inputType="textMultiLine"
android:textColor="#color/colorPrimaryDark"
android:textColorHint="#color/colorAccent"
tools:ignore="HardcodedText"/>
<!--android:text="Trd#sm20"-->
</android.support.design.widget.TextInputLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/button_test_send"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_alignParentEnd="true"
android:layout_alignParentRight="true" android:layout_alignParentTop="true"
android:background="#color/colorAccent"
android:text="Send"
android:textColor="#color/white"
android:textSize="12sp"/>
<Button
android:id="#+id/button_test_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/button_test_send"
android:layout_marginEnd="6dp"
android:layout_marginRight="6dp"
android:layout_toLeftOf="#+id/button_test_send" android:layout_toStartOf="#+id/button_test_send"
android:background="#color/colorAccent"
android:text="Cancel"
android:textColor="#color/white"
android:textSize="12sp"/>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
You are setting onClickListener to spinner thus it's being clicked by the first item. Rater you should use onItemSelectedListener
//Step-1 Experimental Test
popupSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> adapterView, View view, int position, long l) {
Toast.makeText(SolveTest.this, String.valueOf(position), Toast.LENGTH_LONG).show();
}
#Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
try this one
#Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
Object item = arg0.getItemAtPosition(arg2);
if (item!=null) {
Toast.makeText(MainActivity.this, item.toString(),
Toast.LENGTH_SHORT).show();
}
Toast.makeText(MainActivity.this, "Selected",
Toast.LENGTH_SHORT).show();
}
#Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
My Listview is not responding to click event.I'm attaching the layout and java file,please help me out to figure out this.
Thanks in advance.
Layout file
<?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="match_parent"
android:background="#drawable/border_green"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin" >
<TextView
android:id="#+id/txt_mseTitle"
style="#style/pageTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:text="#string/report" />
<View
android:id="#+id/txt_mseView"
android:layout_width="match_parent"
android:layout_height="2dip"
android:layout_below="#+id/txt_mseTitle"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#2E9AFE" />
<EditText
android:id="#+id/edt_OrderLst_Search"
style="#style/EditTextAppTheme"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/txt_mseView"
android:layout_marginLeft="3dp"
android:layout_marginTop="22dp"
android:gravity="center"
android:hint="#string/search" />
<HorizontalScrollView
android:id="#+id/scroll_full"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/edt_OrderLst_Search" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/lay_fullTitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:background="#000000"
android:orientation="horizontal"
android:padding="5dp" >
<TextView
style="#style/textRegular_list"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_weight=".3"
android:text="#string/mpr_po_no"
android:textStyle="bold" >
</TextView>
<TextView
style="#style/textRegular_list"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_weight=".3"
android:text="#string/mprrcptno"
android:textStyle="bold" >
</TextView>
<TextView
style="#style/textRegular_list"
android:layout_width="130dp"
android:layout_height="wrap_content"
android:layout_weight=".3"
android:text="#string/mpr_vendor_no"
android:textStyle="bold" >
</TextView>
</LinearLayout>
<ListView
android:id="#+id/lstSelOrder"
style="#style/ListViewAppTheme.White"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ListView>
</LinearLayout>
</HorizontalScrollView>
</RelativeLayout>
.java File
This is my class file where onItemClickListener and also long click doesn't respond to click event
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.mprreport);
registerBaseActivityReceiver();
LayoutInflater inflater = getLayoutInflater();
toastLayout = inflater.inflate(R.layout.toast,
(ViewGroup) findViewById(R.id.toast_layout_root));
toastText = (TextView) toastLayout.findViewById(R.id.text);
lstSel = (ListView) findViewById(R.id.lstSelOrder);
edtSearch = (EditText) findViewById(R.id.edt_OrderLst_Search);
dbhandler = new DatabaseHandler(this);
// Inflating List
dbhandler.getReadableDatabase();
List<MPR_Trans> lstTemp = dbhandler.getAllPoTrans();
dbhandler.closeDatabase();
transAdap = new TransactionAdapter(MprReport.this, lstTemp);
lstSel.setAdapter(transAdap);
lstSel.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// TODO Auto-generated method stub
Intent i = new Intent(MprReport.this, MprForPrint.class);
startActivity(i);
}
});
edtSearch.addTextChangedListener(new TextWatcher() {
#Override
public void onTextChanged(CharSequence cs, int arg1, int arg2,
int arg3) {
MprReport.this.transAdap.getFilter().filter(cs);
}
#Override
public void beforeTextChanged(CharSequence arg0, int arg1,
int arg2, int arg3) {
// TODO Auto-generated method stub
}
#Override
public void afterTextChanged(Editable edtxt) {
// TODO Auto-generated method stub
}
});
lstSel.setOnItemLongClickListener(new OnItemLongClickListener() {
// setting onItemLongClickListener and passing the
// position to the function
#Override
public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
final int position, long arg3) {
final AlertDialog.Builder alertDialog = new AlertDialog.Builder(
MprReport.this);
alertDialog.setTitle("Confirmation");
alertDialog.setIcon(R.drawable.warning);
alertDialog.setCancelable(false);
alertDialog.setPositiveButton("Yes",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
MPR_Trans mpr_Trans = new MPR_Trans();
mpr_Trans = (MPR_Trans) lstSel
.getItemAtPosition(position);
String poNo = mpr_Trans.getPoNumber();
String rcptNo = mpr_Trans.getReceiptNumber();
// Deleting from Temp table
dbhandler.getWritableDatabase();
dbhandler.deleteFromMprTransTable(poNo, rcptNo);
dbhandler.closeDatabase();
dbhandler.getReadableDatabase();
List<MPR_Trans> lstTemp = dbhandler
.getAllPoTrans();
dbhandler.closeDatabase();
transAdap = new TransactionAdapter(
getApplicationContext(), lstTemp);
lstSel.setAdapter(transAdap);
transAdap.notifyDataSetChanged();
}
});
alertDialog.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
}
});
alertDialog.setMessage("Do you want Delete this Item ?");
alertDialog.show();
return true;
}
});
}
#Override
protected void onDestroy() {
super.onDestroy();
unRegisterBaseActivityReceiver();
}
I had this problem just this morning !
you have some clickable view inside item of your listview, for me i had a radioButton
try add this to your clickable view and it will work :
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
You may find this post helpful :
OnItemCLickListener not working in listview
Good luck
my code is to change edittext to bold or italic .
this code to write a text in editText and send it to another layout when touch in image1
this has intent to take text and size of text
i want another intent to take the bold or italic also .
public class Graduation extends ActionBarActivity {
Button button;
ImageView imageView ;
Spinner spinner;
int fontSizeInt;
String[]items = { "12", "16", "18", "20", "24", "28" , "30" };
int fontSizeFamily;
EditText et;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.graduation);
spinner = (Spinner)findViewById(R.id.spinner);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(
this, android.R.layout.simple_spinner_item, items);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(
new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
int position = spinner.getSelectedItemPosition();
try
{
fontSizeInt = Integer.parseInt(items[position]);
}
catch (NumberFormatException e)
{
fontSizeInt = 12; // Default size.
}
et.setTextSize(TypedValue.COMPLEX_UNIT_SP, (float) fontSizeInt);
// TODO Auto-generated method stub
}
#Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
addListenerOnImageg1() ;
addListenerOnButton1();
addListenerOnButton2();
et = (EditText) findViewById(R.id.et);
}
public void addListenerOnButton1() {
final Context context = this;
button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
et.setTypeface(null,Typeface.BOLD);
}
}); }
public void addListenerOnButton2() {
final Context context = this;
button = (Button) findViewById(R.id.button2);
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
et.setTypeface(null,Typeface.ITALIC);
}
}); }
public void addListenerOnImageg1() {
final Context context = this;
imageView = (ImageView) findViewById(R.id.g1);
imageView.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
Intent intent = new Intent(context, g1.class);
startActivity(intent);
Intent intent1 = new Intent(context , g1.class);
intent1.putExtra("fn" , et.getText().toString());
intent1.putExtra("font_size", fontSizeInt);
startActivity(intent1);
// here is the intent I want to take a style also to another layout
}
}); }
also i have .xml file which has all the content i want ..
something like this
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/backf"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter your Text Here : "
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="#+id/et"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" >
<requestFocus />
</EditText>
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TableRow>
<Spinner
android:id="#+id/spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:drawable/btn_dropdown"
android:spinnerMode="dropdown" />
<Button
android:id="#+id/button1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textStyle="bold"
android:text="B" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="italic"
android:text="I" />
</TableRow>
</TableLayout>
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="choose your card : "
android:textAppearance="?android:attr/textAppearanceLarge" />
<ImageView
android:id="#+id/g1"
android:layout_width="122dp"
android:layout_height="111dp"
android:clickable="true"
android:onClick="onClick"
android:src="#drawable/g1" />
<ImageView
android:id="#+id/g2"
android:layout_width="122dp"
android:layout_height="111dp"
android:clickable="true"
android:onClick="onClick"
android:src="#drawable/g2" />
<ImageView
android:id="#+id/g3"
android:layout_width="122dp"
android:layout_height="111dp"
android:clickable="true"
android:onClick="onClick"
android:src="#drawable/g3" />
<ImageView
android:id="#+id/g4"
android:layout_width="122dp"
android:layout_height="111dp"
android:clickable="true"
android:onClick="onClick"
android:src="#drawable/g4" />
<ImageView
android:id="#+id/g5"
android:layout_width="122dp"
android:layout_height="111dp"
android:clickable="true"
android:onClick="onClick"
android:src="#drawable/g5" />
<ImageView
android:id="#+id/g6"
android:layout_width="122dp"
android:layout_height="111dp"
android:clickable="true"
android:onClick="onClick"
android:src="#drawable/g6" />
<ImageView
android:id="#+id/g7"
android:layout_width="122dp"
android:layout_height="111dp"
android:clickable="true"
android:onClick="onClick"
android:src="#drawable/g7" />
</LinearLayout>
</ScrollView>
so my text goes to another layout with no change so when i click bold button the change happen on editText but when i click image the text go to image1 layout without bold