inflate custom Gallery Layout change properties fail - android

I tried to build my first custom gui element but I get problems when I try to change appearance or adapter (using Gallery) later in code.
My Problem: I can't change Custom Gallery properties
My actual Code:
First I create an XML which is the widget customGallery.xml
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<ImageButton android:id="#+id/toLeft"
android:background="#drawable/arrow_left"
android:layout_width="wrap_content"
android:layout_height="40dip"
android:layout_marginBottom="1dip" />
<Gallery
android:id="#+id/gallery"
android:layout_width="fill_parent"
android:layout_height="40dip"
android:layout_toRightOf="#+id/toLeft"
android:spacing="40dip"
android:scrollbars="horizontal"/>
<ImageButton android:id="#+id/toRight"
android:background="#drawable/arrow_right"
android:layout_width="wrap_content"
android:layout_height="40dip"
android:layout_toRightOf="#+id/gallery" />
</merge>
Later i create a test.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/lin_layout"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.Test.GallerySlider
android:id="#+id/choose"
android:layout_span="2"
android:layout_width="300dip"
android:layout_height="wrap_content" />
</LinearLayout>
My next Step was to include this custom Widget into my project and change the adapter from my Widget:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
LinearLayout lineLayout = (LinearLayout) findViewById(R.id.lin_layout);
ViewStub st3 = new ViewStub(TestwidgetActivity.this);
LinearLayout.LayoutParams paramst3 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
lineLayout.addView(st3,paramst3);
st3.setLayoutResource(R.layout.test);
View st3InflaView =st3.inflate();
GallerySlider gSlider= (GallerySlider) st3InflaView.findViewById(R.id.choose);
gSlider.setNewAdapter( new ArrayAdapter<String>(this, android.R.layout.customGallery, new String[] {"1 ","2","3","4"}));
}
This is the Widgetclass I wrote:
public class GallerySlider extends RelativeLayout implements OnClickListener {
private ArrayAdapter<String> adapter;
private Gallery gallery;
private ImageButton toLeftBtn = null;
private ImageButton toRightbtn = null;
public GallerySlider(Context context) {
super(context, null);
init(context);
}
public GallerySlider(Context context, AttributeSet attrs) {
super(context, attrs);
init(context);
}
public GallerySlider(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs);
init(context);
}
public void init(Context ctx){
LayoutInflater inflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE) ;
inflater.inflate(R.layout.customGallery, this, true);
toLeftBtn = (ImageButton) findViewById(R.id.toLeft);
toLeftBtn.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
if(gallery.getSelectedItemPosition() > 0){
gallery.setSelection(gallery.getSelectedItemPosition()-1);
}
}
});
toRightbtn = (ImageButton) findViewById(R.id.toRight);
toRightbtn.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
if(gallery.getSelectedItemPosition() < gallery.getAdapter().getCount()-1){
gallery.setSelection(gallery.getSelectedItemPosition()+1);
}
}
});
adapter = new ArrayAdapter<String>(ctx, android.R.layout.simple_gallery_item, new String[] {"1","1",
"1")});
gallery = (Gallery) findViewById(R.id.gallery);
gallery.setBackgroundResource(R.drawable.h_sliderl);
gallery.setAdapter(adapter);
}
#Override
public void onClick(DialogInterface dialog, int which) {
switch(which){
case R.id.toLeft: gallery.setSelection(gallery.getFocusedChild().getId()-1);
break;
case R.id.toRight: gallery.setSelection(gallery.getFocusedChild().getId()+1);
break;
}
}
public void setNewAdapter(ArrayAdapter<String> _adapter){
gallery.setAdapter(_adapter);
((ArrayAdapter) gallery.getAdapter()).notifyDataSetChanged ();
}
}
If I call setNewAdapter(ArrayAdapter _adapter) nothing change.. . I also tried to change the size of the gallery but it also fails(nothig happen). Is my approach false?
greetings marcel

The first thing I can detect is that you are creating your custom view two times.
The first creation occurs with the ViewStub when you set the layout.
And the second one, which doesn't get added to the contentView when you inflate R.layout.test.
You are setting the adapter to the second custom view which it isn't added to the view hierarchy.

Related

Show loader on Spinner (Dropdown) when it is fetching data from web service

In the image above, I have shown that when the user touches the drop-down spinner it will call the web api for getting data for the spinner. Then, that moment, I want to show the loader only on the spinner view on the left or right somewhere on the view itself like in the image, rather than on whole screen when it is getting data from the web service dynamically and hide that progress bar later when web service completely hit at the end (Ignore that search bar in image).
Just create an custom adapter for your spinner. Follow the instructions found here How to create Spinner-list using CustomAdapter in android .
Put the loading view in the layout inflated in the getView method in the adapter, and manipulate it via a callback from your async task used for fetching the result.
In this i am showing loader on start button and hiding loader when stop button is pressed so you can use according to your need.So , for this i have made three class CustomSpinner,Spinner_Custom_adapter and Activity class for using it
In main layout file
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:orientation="vertical">
<www.your_packagename.com.spinnerwithloaderex.CustomSpinner
android:id="#+id/custm_spnr"
android:layout_width="120dp"
android:layout_height="40dp"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:background="#drawable/dropdown_create_sales"
android:paddingRight="15dp"
android:text="Hello World!" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp">
<Button
android:id="#+id/start_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start" />
<Button
android:id="#+id/stop_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Stop" />
</LinearLayout>
</LinearLayout>
CustomSpinner class
public class CustomSpinner extends android.support.v7.widget.AppCompatSpinner {
private Spinner_Custom_adapter spinner_custom_adapter;
public CustomSpinner(Context context) {
super(context);
}
public CustomSpinner(Context context, int mode) {
super(context, mode);
}
public CustomSpinner(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CustomSpinner(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public CustomSpinner(Context context, AttributeSet attrs, int defStyleAttr, int mode) {
super(context, attrs, defStyleAttr, mode);
}
public CustomSpinner(Context context, AttributeSet attrs, int defStyleAttr, int mode, Resources.Theme popupTheme) {
super(context, attrs, defStyleAttr, mode, popupTheme);
}
public void setItems(Activity activity, ArrayList<String> spnr_Arr) {
spinner_custom_adapter = new Spinner_Custom_adapter(activity, spnr_Arr);
setAdapter(spinner_custom_adapter);
}
public Spinner_Custom_adapter getSpinner_custom_adapter() {
return spinner_custom_adapter;
}
public void showLoader() {
setEnabled(false);
spinner_custom_adapter.showLoader(true, true);
}
public void dismissLoader() {
setEnabled(true);
spinner_custom_adapter.showLoader(false, true);
}
}
Custom_Adapter class
public class Spinner_Custom_adapter<T> extends ArrayAdapter<T> {
private LayoutInflater flater;
private ProgressBar spinner_progress;
private TextView txtTitle;
private Boolean showOrNot = false;
Spinner_Custom_adapter(Activity context, ArrayList<T> list) {
super(context, R.layout.loader_spinner_lt, R.id.title, list);
flater = context.getLayoutInflater();
}
#NonNull
#Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = flater.inflate(R.layout.loader_spinner_lt, parent, false);
}
Object object = getItem(position);
String rowItem = null;
if (object instanceof String) {
rowItem = (String) object;
}
TextView txtTitle = (TextView) convertView.findViewById(R.id.title);
txtTitle.setText(rowItem);
ProgressBar spinner_progress = (ProgressBar) convertView.findViewById(R.id.spinner_progress);
this.txtTitle = txtTitle;
this.spinner_progress = spinner_progress;
showLoader(showOrNot, false);
return convertView;
}
void showLoader(Boolean showOrNot, boolean notifyListOrNot) {
if (txtTitle != null && spinner_progress != null) {
this.showOrNot = showOrNot;
spinner_progress.setVisibility(showOrNot ? View.VISIBLE : View.GONE);
if (notifyListOrNot) {
notifyDataSetChanged();
}
}
}
}
Spinner single view layout xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:orientation="horizontal">
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/title"
style="?android:attr/spinnerDropDownItemStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/spinner_progress"
android:ellipsize="end"
android:singleLine="true"
android:text="Strawberry"
android:textColor="#CC0033"
android:textSize="16dp" />
<ProgressBar
android:id="#+id/spinner_progress"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:visibility="gone" />
</RelativeLayout>
and for using it
custm_spnr = (CustomSpinner) findViewById(R.id.custm_spnr);
ArrayList<String> items = new ArrayList<>();
items.add("Abcdefg");
items.add("hijklm");
items.add("nopqr");
items.add("stu");
items.add("vwxyza1b1c1");
items.add("d1e1f11g1h1");
custm_spnr.setItems(MainActivity.this, items);
findViewById(R.id.start_btn).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
custm_spnr.showLoader();
}
});
findViewById(R.id.stop_btn).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
custm_spnr.dismissLoader();
}
});

How to force GridView to load cells

GridView is scrolled programmatically, and no new item appears coming up from the bottom.
I tried to update with the following line, but it does not force GridView to load new items.
imageAdapter.notifyDataSetChanged();
gridview.invalidateViews();
gridview.setAdapter(imageAdapter);
Simplified the app, now the scrolling can be fired with button click, but the upcoming empty items are still appearing. Here is some code:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final CustomGridView gridview = (CustomGridView) findViewById(R.id.gridView1);
final ImageAdapter imageAdapter = new ImageAdapter(this);
gridview.setAdapter(imageAdapter);
gridview.setNumColumns(3);
LinearLayout.LayoutParams linearParams = (LinearLayout.LayoutParams)gridview.getLayoutParams();
linearParams.width=66*3;
gridview.setLayoutParams(linearParams);
final Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
gridview.scrollBy(0, 44);
}
});
}
public class ImageAdapter extends BaseAdapter {
private Context mContext;
public ImageAdapter(Context c) {
mContext = c;
}
public int getCount() {
return 300;
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
// create a new ImageView for each item referenced by the Adapter
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
if (convertView == null) {
// if it's not recycled, initialize some attributes
imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(66, 66));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(0, 0, 0, 0); // 8 8 8 8
} else {
imageView = (ImageView) convertView;
}
imageView.setImageResource(R.drawable.asdf);
return imageView;
}
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.j4nos.moviebuffs12.MainActivity">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="#+id/button"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<HorizontalScrollView
android:id="#+id/horizontalScrollView"
android:layout_width="198dp"
android:layout_height="match_parent"
android:layout_marginTop="66dp"
android:layout_marginLeft="0dp"
android:layout_marginBottom="0dp">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<com.j4nos.moviebuffs12.CustomGridView
android:id="#+id/gridView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="0dp"
android:columnWidth="66dp"
android:horizontalSpacing="0dp"
android:scrollbarAlwaysDrawHorizontalTrack="true"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:scrollbars="horizontal"
android:stretchMode="none"
android:verticalSpacing="0dp"
android:listSelector="#null"
android:scaleType="centerCrop">
</com.j4nos.moviebuffs12.CustomGridView>
</LinearLayout>
</HorizontalScrollView>
</RelativeLayout>
public class CustomGridView extends GridView {
public CustomGridView(Context context) {
super(context);
}
public CustomGridView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CustomGridView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
/* ADD THIS */
#Override
public int computeVerticalScrollOffset() {
return super.computeVerticalScrollOffset();
}
}
I think the problem is with the way you are scrolling:
gridview.scrollBy(0, 44);
This moves the gridview, not the content of the gridview. You can verify this by adding the following into your layout inside the CustomGridView component:
android:fastScrollAlwaysVisible="true"
Now you can see it's not the gridview content that is being interacted with on the button press.
Instead, I suggest you try to use:
gridview.scrollListBy(44);
if your API level allows it.

How to set WearableListView item height

I make WearableListView list. Problem is that setting android:layout_height="20dp" doesn't help
How to set height in this case? In Android Wear sample projects Notifications and Timer they also just set atribute android:layout_height="80dp". But I tried to set in the projects android:layout_height="20dp" but it didn't help! (below is my project source code):
list_item.xml:
<?xml version="1.0" encoding="utf-8"?>
<base.mobitee.com.mobiteewatch.adapter.HolesListItemLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="20dp"
android:gravity="center_vertical" >
<TextView
android:id="#+id/text_hole"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:gravity="center"
android:textSize="#dimen/list_item_text_size" />
</base.mobitee.com.mobiteewatch.adapter.HolesListItemLayout>
HolesListItemLayout.java:
public class HolesListItemLayout extends LinearLayout
implements WearableListView.OnCenterProximityListener {
private TextView mName;
private final int mFadedTextColor;
private final int mChosenTextColor;
public HolesListItemLayout(Context context) {
this(context, null);
}
public HolesListItemLayout(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public HolesListItemLayout(Context context, AttributeSet attrs,
int defStyle) {
super(context, attrs, defStyle);
mFadedTextColor = getResources().getColor(R.color.grey);
mChosenTextColor = getResources().getColor(R.color.black);
}
// Get references to the icon and text in the item layout definition
#Override
protected void onFinishInflate() {
super.onFinishInflate();
mName = (TextView) findViewById(R.id.text_hole);
}
#Override
public void onCenterPosition(boolean animate) {
mName.setTextSize(18);
mName.setTextColor(mChosenTextColor);
}
#Override
public void onNonCenterPosition(boolean animate) {
mName.setTextColor(mFadedTextColor);
mName.setTextSize(14);
}
}
HolesListAdapter.java:
public class HolesListAdapter extends WearableListView.Adapter {
private final Context mContext;
private final LayoutInflater mInflater;
public HolesListAdapter(Context context) {
this.mContext = context;
mInflater = LayoutInflater.from(context);
}
#Override
public WearableListView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
return new WearableListView.ViewHolder(
mInflater.inflate(R.layout.list_item_hole, null));
}
#Override
public void onBindViewHolder(WearableListView.ViewHolder holder, int position) {
TextView text = (TextView) holder.itemView.findViewById(R.id.text_hole);
text.setText(mContext.getString(R.string.hole_list_item) + " " + (position + 1));
text.setTextColor(mContext.getResources().getColor(android.R.color.black));
holder.itemView.setTag(position);
}
#Override
public int getItemCount() {
return Preferences.HOLES;
}
}
The WearableListView is hard-coded to only display three items at a time - it measures the item height by dividing the list view's height by three ... so there isn't a practical way of doing what you want.
I suggest making the text font larger ...
I've got idea. Insert list into FrameLayout container. And by changing height of container list item height is changed. Result:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="90dp"
android:layout_centerInParent="true">
<android.support.wearable.view.WearableListView
android:id="#+id/wearable_list_game_options"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:dividerHeight="0dp"
android:scrollbars="none"/>
</FrameLayout>
</RelativeLayout>
Add one LinearLayout inside and set
android:layout_height="50dp"
android:layout_margin="5dp"

Android development - make a spinner look like a spinner

I'm creating a spinner programmatically in my activity class. The "Spinner" looks like a dropdown rather than a spinner. I guess I want it to look more like a picker (ie date picker / time picker / number picker) where you can spin through all the text options.
I would use a picker type widget if there was a text picker available but I can't seem to find such a widget - only a number picker. Here is the code I'm using in my activity.
ArrayAdapter <String>lv1List = new ArrayAdapter<String>(this.getApplicationContext(),android.R.layout.simple_spinner_item, new String[]{"item 1","item 2","item 3"});
Spinner sp = new Spinner(getApplicationContext());
sp.setAdapter(lv1List);
sp.setOnItemSelectedListener(this);
Take a look at Android Wheel. You can have text or pretty much anything on it. Works perfectly.
Quick ( and inefficient) example if you want to create your own spinner. (Works with List View Adapters):
Layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<FrameLayout android:id="#+id/container"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center_vertical"
/>
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:orientation="vertical">
<Button android:id="#+id/btn_up"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="up"/>
<Button android:id="#+id/btn_down"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="down"/>
</LinearLayout>
</LinearLayout>
CustomSpinner Class:
public class CustomSpinner extends FrameLayout{
// ------------------------------ FIELDS ------------------------------
private FrameLayout mContainer;
private SpinnerAdapter mAdapter;
private int index = 0;
// --------------------------- CONSTRUCTORS ---------------------------
public CustomSpinner(Context context) {
super(context);
init(context);
}
public CustomSpinner(Context context, AttributeSet attrs) {
super(context, attrs);
init(context);
}
private void init(Context context){
this.addView(LayoutInflater.from(context).inflate(R.layout.custom_spinner,this,false));
findViewById(R.id.btn_up).setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
index--;
refresh();
}
});
findViewById(R.id.btn_down).setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
index++;
refresh();
}
});
mContainer = (FrameLayout) findViewById(R.id.container);
}
// -------------------------- OTHER METHODS --------------------------
public void setAdapter(SpinnerAdapter adapter) {
this.mAdapter = adapter;
refresh();
}
private void refresh() {
//----needs recycling for better performance---
//---now, we'll just clear up--
mContainer.removeAllViews();
//---do we need to refresh ? -----
if(mAdapter == null || mAdapter.getCount() == 0){return;}
//--clamp index--
index = Math.max(0,index);
index = Math.min(mAdapter.getCount() - 1, index);
//--get view and show it-----
View currentView = mAdapter.getView(index,null,mContainer);
mContainer.addView(currentView);
}
}
Use Case:
Layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<com.example.CustomSpinner android:id="#+id/custom_spinner"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
/>
</LinearLayout>
Activity:
public class MyActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,
new String[]{"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"});
((CustomSpinner)findViewById(R.id.custom_spinner)).setAdapter(adapter);
}
}

CheckedTextView checkmark in ListView row not showing up

I have a problem with the Checkmark of my ListView row layout. The checkmark doesn't show up when the ListItem is clicked even though the ListView works (the interaction works). How can i fix this problem?
You will want to make you custom row layout that is checkable.
First you need to create a custom layout that implements Checkable:
public class CheckableLinearLayout extends LinearLayout implements Checkable {
private Checkable mCheckable;
public CheckableLinearLayout(Context context) {
this(context, null);
}
public CheckableLinearLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
#Override
public boolean isChecked() {
return mCheckable == null ? false : mCheckable.isChecked();
}
#Override
protected void onFinishInflate() {
super.onFinishInflate();
// Find Checkable child
int childCount = getChildCount();
for (int i = 0; i < childCount; ++i) {
View v = getChildAt(i);
if (v instanceof Checkable) {
mCheckable = (Checkable) v;
break;
}
}
}
#Override
public void setChecked(boolean checked) {
if(mCheckable != null)
mCheckable.setChecked(checked);
}
#Override
public void toggle() {
if(mCheckable != null)
mCheckable.toggle();
}
}
After this layout is inflated it looks through it's children for one that is checkable (like a CheckedTextView or CheckBox), other than that it is quite simple.
Next use it in a layout:
<your.package.name.CheckableLinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:gravity="center_vertical" >
<TextView
android:id="#+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<CheckedTextView
android:id="#+id/text2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checkMark="?android:attr/textCheckMark"
android:gravity="center_vertical"
android:paddingLeft="6dp"
android:paddingRight="6dp" />
</your.package.name.CheckableLinearLayout>
Notice that you cannot just use CheckableLinearLayout, since it is not a built-in Android View you need tell the compiler where it is. Save this as checkable_list_row.xml, for example.
Lastly use this new layout like you would with any other custom layout.
adapter = new MySimpleCursorAdapter(this, R.layout.checkable_list_row, cursor,
new String[] { Database.KEY_DATE , Database.KEY_NAME },
new int[] {R.id.text1, R.id.text2}, 0);
Hope that helps!

Categories

Resources