How to remove the Shadow of the Spinner DropDownView - android

I use the widget Spinner with a custom adapter and custom views in spinnerMode dropdown. My problem is that I cannot remove the default shadow that casts the dropdown of the Spinner.
Here is the code inside the Activity
mSpinner = (Spinner)findViewById(R.id.spinner);
setSpinnerData();
customSpinnerAdapter = new CustomSpinnerAdapter(this,R.layout.spinner_item,CustomListViewValuesArr );
mSpinner.setAdapter(customSpinnerAdapter);
mSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
itemSelect(pos);
}
#Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
Also this is the Spinner inside the Layout of the Activity:
<Spinner
android:id="#+id/spinner"
android:layout_centerInParent="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:spinnerMode="dropdown"
android:background="#null"
android:padding="0dp"
android:layout_margin="15dp"
android:dropDownVerticalOffset="#dimen/vertical_offset"/>
I use my own custom Adapter :
public class CustomSpinnerAdapter extends ArrayAdapter {
public ArrayList CustomListViewValuesArr;
LayoutInflater inflater;
Typeface myTypeFace;
SpinnerItem item = null;
public CustomSpinnerAdapter(Context context, int textViewResourceId, ArrayList CustomListViewValuesArr) {
super(context, textViewResourceId, CustomListViewValuesArr);
this.CustomListViewValuesArr = CustomListViewValuesArr;
this.inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
this.myTypeFace = Typeface.createFromAsset(context.getAssets(),"fonts/OpenSans-Regular.ttf");
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
return getCustomView(position, convertView, parent);
}
#Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
return getCustomDropDownView(position, convertView, parent);
}
public View getCustomDropDownView(int position, View convertView, ViewGroup parent) {
Log.d("","CustomListViewValuesArr" + position);
/********** Inflate spinner_rows.xml file for each row ( Defined below ) ************/
View row = inflater.inflate(R.layout.simple_spinner_dropdown_item, parent, false);
item = (SpinnerItem) CustomListViewValuesArr.get(position);
/***** Get each Model object from Arraylist ********/
TextView label = (TextView)row.findViewById(R.id.spinner_drop_down);
// Default selected Spinner item
label.setText(item.getFilterName());
label.setTypeface(myTypeFace);
return row;
}
public View getCustomView(int position, View convertView, ViewGroup parent) {
Log.d("","CustomListViewValuesArr" + position);
/********** Inflate spinner_rows.xml file for each row ( Defined below ) ************/
View row = inflater.inflate(R.layout.spinner_item, parent, false);
item = (SpinnerItem) CustomListViewValuesArr.get(position);
/***** Get each Model object from Arraylist ********/
TextView label = (TextView)row.findViewById(R.id.spinner_item);
TextView hint = (TextView)row.findViewById(R.id.spinner_hint);
hint.setTypeface(myTypeFace);
// Default selected Spinner item
label.setText(item.getFilterName());
label.setTypeface(myTypeFace);
return row;
}
}
And finally I use custom views for the Dropdown
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:elevation="-6dp"
android:layout_height="35dp">
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
style="#style/spinnerDropDownItemStyle"
android:singleLine="true"
android:id="#+id/spinner_drop_down"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:textColor="#color/spinner_font_color"
android:layout_marginLeft="20dp"
android:textSize="14sp"
android:layout_marginStart="20dp"
android:ellipsize="marquee">
</TextView >
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/color_hint_change_pass"/>
and for the Spinner Item
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:ellipsize="marquee"
android:background="#drawable/spinners_background"
style="#style/spinnerItemStyle"
android:layout_height="35dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/spinner_hint"
android:gravity="center"
android:textStyle="bold"
android:textColor="#color/spinner_font_color"
android:textSize="14sp"
android:id="#+id/spinner_hint"
android:layout_marginRight="5dp"
android:layout_alignParentLeft="true"
android:layout_marginLeft="20dp"
android:layout_marginStart="20dp"
android:layout_alignTop="#+id/spinner_item" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/spinner_item"
android:textColor="#color/spinner_header_color"
android:gravity="center"
android:text="sss"
android:textSize="14sp"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/spinner_hint"
android:layout_toEndOf="#+id/spinner_hint" />
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:src="#drawable/down_arrow_spinner"
android:layout_marginRight="17dp"
android:layout_marginEnd="1dp"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:id="#+id/imageView2" />
What I have tried and didn't worked :
Add Elevation to 0dp in the Spinner widget
Add null background to Spinner
Thanks in Advance !

Use this:
android:popupElevation="0dp"

Eventually I used an attributed of a spinner android:popupBackground="#null" with this the background of the pop up of the spinner is removed so and the shadow does. The only thing the I had to change was to Assign a background of #fff in my custom spinner dropdown item. So I changed it like this:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:background="#fff"
android:layout_height="35dp">
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
style="#style/spinnerDropDownItemStyle"
android:singleLine="true"
android:id="#+id/spinner_drop_down"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:textColor="#color/spinner_font_color"
android:layout_marginLeft="20dp"
android:textSize="14sp"
android:layout_marginStart="20dp"
android:ellipsize="marquee">
</TextView >
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/color_hint_change_pass"/>
</RelativeLayout >

Related

Why is my listview not expanding to accommodate a larger row size?

I have a listview that I want the user to be able to delete items from. If the user holds on a row long enough, the row's checkbox is made visible. However, the listview doesn't grow to accommodate the (now taller) row despite there being plenty of space. I had this issue before when the listview was in a scrollview but that's no longer the case. I understand I can reformat the text as a bandage solution, but I want to understand what is happening.
Here is the listview before and after the first entry is held. You can see the listview's height stays the same and doesn't expand to accommodate the two entries:
Here is the listView:
<ListView
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
Here is the listView item layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns="https://"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp">
<CheckBox
android:id="#+id/deleteCheckBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone" />
<TextView
android:id="#+id/number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="5dp"
android:textColor="#android:color/black"
android:textSize="18sp" />
<TextView
android:id="#+id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:paddingRight="5dp"
android:textColor="#android:color/darker_gray"
android:textSize="18sp" />
</LinearLayout>
Here is how the layout is being inflated in my custom adapter:
public class CustomAdapter extends ArrayAdapter<CustomlistEntry> {
public CustomAdapter(Context context, ArrayList<CustomlistEntry> entries) {
super(context, 0, entries);
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
if(convertView == null) {
convertView = LayoutInflater.from(getContext()).inflate(R.layout.activity_custom_listview, parent, false);
}
CustomlistEntry entry = getItem(position);
TextView tvNumber = convertView.findViewById(R.id.number);
TextView tvDate = convertView.findViewById(R.id.date);
tvNumber.setText(entry.getNumber());
tvDate.setText(entry.getDateString());
return convertView;
}
}
and finally the adapter being set:
CustomAdapter adapter = new CustomAdapter(App.getApp(), arrayListSorted);
final ListView listView = activity.findViewById(R.id.listView);
listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
#Override
public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
final int pos, long id) {
arg1.findViewById(R.id.deleteCheckBox).setVisibility(View.VISIBLE);
CustomAdapter adapter = (CustomAdapter)listView.getAdapter();
return true;
}
});
listView.setAdapter(adapter);

Custom Spinner with default down arrow in it

I have a custom layout for spinner. Its both selected and dropdown list item's background color will change depending on user demand. So i am changing depending on their values.. so far so good. But the problem is since i am using custom layout or changing background color, there is no arrow to show that it is a spinner. When i add arrow from layout then all even dropdown list have that arrow with them. I can manipulate it by setting arrow's background to null for drop down items but it is not a good way and dont always work. So how can i show spinner default arrow with my custom spinner without using spinner style. Dont forget that i am changing background of every item.
Here is my custom_spinner.xml
<?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:weightSum="6" android:id="#+id/spinnerMainLayout"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="horizontal" android:layout_width="match_parent"
android:weightSum="14"
android:layout_height="wrap_content">
<TextView
android:layout_width="0dp" android:layout_marginTop="8dp"
android:layout_height="wrap_content" android:layout_marginLeft="10dp"
android:text="New Text" android:textSize="19sp" android:layout_weight="5"
android:layout_gravity="center" android:layout_marginBottom="8dp"
android:gravity="center" android:layout_marginRight="4dp"
android:id="#+id/type" android:typeface="serif"/>
<View
android:layout_width="1dp" android:layout_marginLeft="8dp" android:layout_marginTop="4dp"
android:layout_height="match_parent" android:layout_marginBottom="4dp"
android:background="#666666" />
<TextView
android:layout_width="0dp" android:layout_height="wrap_content"
android:layout_marginTop="8dp" android:layout_weight="9"
android:typeface="serif" android:maxLines="3" android:minLines="2"
android:layout_gravity="center" android:layout_marginBottom="8dp"
android:layout_marginLeft="10dp" android:layout_marginRight="5dp"
android:text="sd" android:textSize="18sp" android:gravity="center_vertical"
android:id="#+id/history" />
</LinearLayout>
</LinearLayout>
and here is my custom spinner class
class CustomSpinner extends ArrayAdapter<String> {
private String[] fixStrs = new String[]{"Definition","Result","Error"};
public CustomSpinner(Context ctx, int txtViewResourceId, String[] objects) {
super(ctx, txtViewResourceId, objects);
//fixStrs = objects;
}
#Override public View getDropDownView(int position, View cnvtView, ViewGroup prnt) {
return getCustomView(position, cnvtView, prnt);
}
#Override public View getView(int pos, View cnvtView, ViewGroup prnt) {
return getCustomView(pos, cnvtView, prnt);
}
public View getCustomView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = getLayoutInflater();
View mySpinner = inflater.inflate(R.layout.custom_spinner, parent, false);
/*LinearLayout spinnerMain = (LinearLayout) mySpinner.findViewById(R.id.spinnerMainLayout);
spinnerMain.setBackgroundColor(Color.parseColor(colors[0]));*/
TextView fixText = (TextView) mySpinner.findViewById(R.id.type);
fixText.setText(fixStrs[position]);
fixText.setTextColor(Color.parseColor(colors[1]));
TextView historyText = (TextView) mySpinner.findViewById(R.id.history);
historyText.setText(history[position]);
historyText.setTextColor(Color.parseColor(colors[1]));
return mySpinner;
}
}
Create a different layout for the spinner dropdown and pass it to the .setDropDownViewResource method of the ArrayAdapter, then you must specify the id of the textview in this layout in the constructor call of your adapter

Spinner popUpBackground cannot setting to transparent color in Android

Working on custom spinner for the first time. I have a spinner with background using nine patch image. Spinnermode is in dialog mode. Now I set custom layout for spinner and spinner item. Run the code but I did not the desired solution. There are corners seeing on the spinner item's background even I have set the background of spinner item . Searched alot but did not find the exact solution. I used code from this site sourcecode form this site their result is perfect but when I tried there whole code did not get the desired result seeing white background in the spinner items.
main.xml
<Spinner
android:id="#+id/spinner1"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_below="#+id/scrollView"
android:layout_marginLeft="20dp"
android:background="#drawable/dropdown_button"
android:paddingLeft="2dp"
android:paddingRight="13dp"
android:paddingTop="5dp"
android:spinnerMode="dialog" />
</RelativeLayout>
spinner_item.xml
<?xml version="1.0" encoding="UTF-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/spinneritem"
android:layout_width="100dp"
android:layout_height="fill_parent"
android:paddingLeft="10dp" />
spinner_item_list
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/blank_buttons"
android:orientation="horizontal" >
<TextView
android:id="#+id/spinneritemlist"
style="#style/SpinnerText"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_vertical|center_horizontal"
android:gravity="center"
android:textColor="#android:color/black" />
</LinearLayout>
**in onCreate()**
ArrayList<CountryInfo> myCountries;
myCountries = populateList();spinner1 = (Spinner) findViewById(R.id.spinner1);
CountryAdapter myAdapter = new CountryAdapter(this, R.layout.spinner_item, myCountries);
spinner1.setAdapter(myAdapter);
function and adapter
public ArrayList<CountryInfo> populateList()
{
ArrayList<CountryInfo> myCountries = new ArrayList<CountryInfo>();
myCountries.add(new CountryInfo("USA")); // Image stored in /drawable
myCountries.add(new CountryInfo("Sweden"));
myCountries.add(new CountryInfo("Canada"));
return myCountries;
}
public class CountryAdapter extends ArrayAdapter<CountryInfo>
{
private Activity context;
ArrayList<CountryInfo> data = null;
public CountryAdapter(Activity context, int resource, ArrayList<CountryInfo> data)
{
super(context, resource, data);
this.context = context;
this.data = data;
}
#Override
public View getView(int position, View convertView, ViewGroup parent)
{ // Ordinary view in Spinner, we use android.R.layout.simple_spinner_item
return super.getView(position, convertView, parent);
}
#Override
public View getDropDownView(int position, View convertView, ViewGroup parent)
{ // This view starts when we click the spinner.
View row = convertView;
if(row == null)
{
LayoutInflater inflater = context.getLayoutInflater();
row = inflater.inflate(R.layout.spinner_item_list, parent, false);
}
CountryInfo item = data.get(position);
if(item != null)
{ // Parse the data from each object and set it.
TextView myCountry = (TextView) row.findViewById(R.id.spinneritemlist);
if(myCountry != null)
myCountry.setText(item.getCountryName());
}
return row;
}
}
My resulting images:
printscreen of perfect result of sample code on their site(not from running their code)
screenshot of non perfect result of sample code(from running their code in my app)
try this
<Spinner
android:id="#+id/spinner1"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_below="#+id/scrollView"
android:layout_marginLeft="20dp"
android:background="#drawable/dropdown_button"
android:paddingLeft="2dp"
android:paddingRight="13dp"
android:paddingTop="5dp"
android:spinnerMode="dialog"
android:popupBackground="#android:color/transparent" />//or desired color or drawable
also try this in spinner_list_item
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:orientation="horizontal" >
<TextView
android:id="#+id/spinneritemlist"
style="#style/SpinnerText"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_vertical|center_horizontal"
android:gravity="center"
android:background="#drawable/blank_buttons"
android:textColor="#android:color/black" />
</LinearLayout>

How to implement a table layout inside a list view

I want to implement a layout which resembles Bank's PassBook. So I thought should I implement table layout inside a list view.
Here is a sample passbook example.
DATE PARTICULARS DEBIT CREDIT BALANCE
12/06/2014 Withdraw 200 10000
11/06/2014 Deposit 200 10200
create xml layout like below
<LinearLayout 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"
tools:context=".MainActivity"
android:orientation="horizontal"
android:weightSum="3">
<TextView
android:id="#+id/date"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="#string/hello_world" />
<TextView
android:id="#+id/action_type"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="#string/hello_world"
android:gravity="center"
android:layout_weight="1"/>
<TextView
android:id="#+id/amount"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="#string/hello_world"
android:gravity="center"
android:layout_weight="1"/>
</LinearLayout>
use this layout as list item for your ListView.
Use an ArrayAdapter for your ListView.
In there, you can inflate the Layout for the items of the list, be it a TableLayout, or something other.
private class MyListAdapter extends ArrayAdapter<SomeObject> {
public MyListAdapter(Context context, int resource, List<SomeObject> someObjectList) {
super(context, resource, someObjectList);
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View view;
//view recycling
if (convertView == null) {
// inflate the single row with whatever layout you like
view = getLayoutInflater().inflate(R.layout.table_row, parent, false);
} else {
view = convertView;
}
SomeObject item = getItem(position);
//fill the view with data
TextView date = (TextView) view.findViewById(R.id.date);
date.setText(item.getDate());
...
return view;
}
...
}
Here's a little to read about ListViews and ArrayAdapter:
https://github.com/thecodepath/android_guides/wiki/Using-an-ArrayAdapter-with-ListView1

List view how to manipulate objects of list adapter item View

adapterListView = new SpecialAdapter(getBaseContext(),list,R.layout.listview_layout,from,to);
headerView = ((LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.jpos_ror_header, null, false);
footerView = ((LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.jpos_ror_footer, null, false);
TextView tin=(TextView)headerView.findViewById(R.id.textViewTinValue);
TextView textViewNameOfPayor=(TextView)headerView.findViewById(R.id.textViewNameOfPayor);
TextView textViewLocation=(TextView)headerView.findViewById(R.id.textViewLocation);
Here is my code in getting object id's from my header and footer. how can i get the view of my list view data adapter without onClick event. i want to do some layout manipulation in viewing of my layout.
<?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" >
<!-- here is my data adapter to be display per item in list view -->
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="#+id/relativeModeOfPaymentCheck"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#000000" >
<LinearLayout
android:id="#+id/linearForCheck"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:orientation="vertical"
android:paddingTop="5dp" >
<TextView
android:id="#+id/textViewModeOfPaymentCheckValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Mode of Payment Value check"
android:layout_marginLeft="15dp"
android:textStyle="bold"
android:textColor="#ffffff" />
</LinearLayout>
<!-- asdasda -->
<LinearLayout
android:id="#+id/linearForAmountModeOfPayment"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/linearCheckDate"
android:orientation="horizontal"
android:weightSum="2" >
<RelativeLayout
android:id="#+id/relativeBlock100"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_weight="1"
android:background="#000000" >
<TextView
android:id="#+id/textViewModAmountCheck"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="AMOUNT"
android:textColor="#ffffff" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/relativeBlock101"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#000000" >
<TextView
android:id="#+id/textViewModeOfPayCheckValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:textColor="#ffffff" />
</RelativeLayout>
</LinearLayout>
<!-- name of check issued -->
<LinearLayout
android:id="#+id/linearForNameCheckIssued"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/linearForCheck"
android:orientation="horizontal"
android:visibility="gone"
android:weightSum="2" >
<RelativeLayout
android:id="#+id/relativeBlock101"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_weight="1"
android:background="#000000" >
<TextView
android:id="#+id/textViewBankNameCheckIssued"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RIZAL COMMERCIAL BANKING CORP."
android:textColor="#ffffff" />
</RelativeLayout>
</LinearLayout>
<!-- CHECK NUMBER -->
<LinearLayout
android:id="#+id/linearCheckNumber"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/linearForNameCheckIssued"
android:visibility="gone"
android:orientation="horizontal" >
<TextView
android:id="#+id/textViewCheckNumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:text="CHECK # : "
android:textColor="#ffffff" />
<TextView
android:id="#+id/textViewCheckNumValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ffffff" />
</LinearLayout>
<!-- CHECK DATE -->
<LinearLayout
android:id="#+id/linearCheckDate"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
<!-- android:visibility="gone" -->
android:layout_below="#+id/linearCheckNumber"
android:orientation="horizontal" >
<TextView
android:id="#+id/textViewCheckDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:text="CHECK DATE : "
android:textColor="#ffffff" />
<TextView
android:id="#+id/textViewCheckDateValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ffffff" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLineForCheck"
android:layout_width="wrap_content"
android:layout_height="2dp"
android:layout_alignParentLeft="true"
android:layout_below="#+id/linearForAmountModeOfPayment"
android:orientation="horizontal" >
<View
android:id="#+id/View201"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ffffff" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
in this adapter i want to manipulate the view of linearlayouts by having LinearLAyout.setVisibility(LinearLayout.GONE or VISIBLE);
Here i think i have some lead from my problem from the answer of himanshu. here is my listview special adapter im having problem how can get the view and viewGroup implementation to my special adapter here is my SpecialAdapter..
public class SpecialAdapter extends SimpleAdapter {
public static TextView tv;
private int[] colors = new int[] { 0xffcccccc , 0xffffffff };
private int[] colors2 = new int[] { 0xffffffff , 0xff000000 };
// Context context;
public SpecialAdapter(Context context, List<HashMap<String, String>> items, int resource, String[] from, int[] to) {
super(context, items, resource, from, to);
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
int colorPos = position % colors.length;
view.setBackgroundColor(colors[colorPos]);
//TextView textView = (TextView)view.findViewById(R.id.textViewModAmountCheck);
//textView.setText("AlvinTest");
return view;
}
Could anyoune tell me i am doing right when im implementing mg getView2.
public View getView2(Context context, int position, View convertView, ViewGroup parent) {
LayoutInflater layoutInflater = LayoutInflater.from(context);//get your layout inflator;
//LayoutInflater inf = LayoutInflater.from(getContext());
if (convertView == null) {
convertView = layoutInflater.inflate(R.layout.listview_layout, null);
}
LinearLayout yyy = (LinearLayout) convertView.findViewById(R.id.linearCheckDate);
yyy.setVisibility(View.GONE);
return convertView;
}
public boolean setViewValue(View view, Cursor cursor, int columnIndex){
int getIndex = cursor.getColumnIndex("Name");
String empname = cursor.getString(getIndex);
tv = (TextView) view;
tv.setTextColor(Color.WHITE);
tv.setText(empname);
if(empname.equals("Any String"))
{
tv.setTextColor(Color.rgb(58, 58, 224));
return true;
}
return false;
}
}
Here's my code when im calling the getView2 from my listAdapter
LayoutInflater inf = LayoutInflater.from(this);
View v = inf.inflate(R.layout.listview_layout, null);
//add magic here bu i don't know how can i get the view of these View and ViewGroup
View itemConvertView = inf.inflate(R.layout.listview_layout, null);
ViewGroup listParent =null; //this.getParent();//(ViewGroup)SelectorView.this.getParent();// null;
adapterListView.getView2(this,0, itemConvertView, listParent);
try this:
Hide your Layout:
YourLayout.setVisibility(View.GONE);
Visible your Layout :
YourLayout.setVisibility(View.VISIBLE);
If i understood your problem correctly, you want to get the first element of the ListView pro grammatically and change its state (Visibility).
You can get the element in ListView by calling getChildAt(int index) method
e.g
LinearLayout yourFirstView = (LinearLayout) listview.getChildAt(0);
Accessing child of the element that reside in first row of the listview.
ViewType view = (ViewType)yourFirstView.findViewById(R.id.elementId);
setting the visiblity
yourFirstView.setVisiblity(View.Gone); // or View.VISIBLE
What I understand from your question is that there is some view in your ListView item which you want to show only if needed. You can do this in the getView method of your adapter where you inflate the custom layout of list item. Something like below
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater layoutInflater = get your layout inflator;
if (convertView == null) {
convertView = layoutInflater.inflate(R.layout.XXXX, null);
}
LinearLayout yyy = (LinearLayout) convertView.findViewById(R.id.member_name_text_view);
yyy.setVisibility(View.Gone)
return convertView;
}

Categories

Resources