To contact us Click HERE
Here you can find the available command set in the shell by typing this at the android shell prompt:
dumpcrash, am, dumpstate, input, itr, monkey, pm, svc, ssltest,debuggerd, dhcpcd, hostapd_cli, fillup, linker, logwrapper, telnetd, iftop, mkdosfs, mount,mv, notify, netstat, printenv, reboot, ps, renice, rm, rmdir,rmmod, sendevent, schedtop,ping, sh, hciattach, sdptool, logcat, servicemanager, dbus-daemon, debug_tool, flash_image, installd,dvz, hostapd, htclogkernel, mountd, qemud, radiooptions, toolbox, hcid,route, setprop, sleep, setconsole, smd, stop, top, start, umount,vmstat, wipe, watchprops, sync, netcfg, Chmod, date, dd, cmp, cat, dmesg, df,getevent, getprop, hd, id, ifconfig, insmod, ioctl, kill,ln, log, lsmod, ls, mkdir, dumpsys, service, playmp3, sdutil,rild, dalvikvm, dexopt, surfaceflinger, app_process, mediaserver, system_server,
27 Haziran 2012 Çarşamba
To contact us Click HERE
In this blog we are selecting multiple images.Here I have created the custom view components and activity used to get the selected images.
1. Custom ViewComponet
< RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> < ImageView android:id="@+id/thumbImage" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" /> < CheckBox android:id="@+id/itemCheckBox" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_alignParentTop="true" /> < /RelativeLayout>
2. SampleActivity
1. Create a ImageAdapter public class ImageAdapter extends BaseAdapter { }
2. Inflate the View mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); convertView = mInflater.inflate(R.layout.mygallert, null); 3. find the required View imageview = (ImageView) convertView.findViewById(R.id.thumbImage); checkbox = (CheckBox) convertView.findViewById(R.id.itemCheckBox);
4. Control the image selection imageview.setBackgroundResource(R.drawable.icon); checkbox.setId(position); checkbox.setChecked(false); checkbox.setOnClickListener(new OnClickListener() { public void onClick(View v) { CheckBox cb = (CheckBox) v; if (cb.isChecked()) { cb.setChecked(true); selectedImage.add(v.getId()); } else { cb.setChecked(false); selectedImage.remove(v.getId()); } } });
4. Track the image selection selectedImage.add(v.getId()); selectedImage.remove(v.getId());
5. displays the selected Image Position Toast.makeText(SampleActivity.this,"" + SampleActivity.this.selectedImage, 10).show();
Sample
public class SampleActivity extends Activity { private ImageAdapter imageAdapter; private Set selectedImage = new HashSet();
/** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); GridView imagegrid = (GridView) findViewById(R.id.PhoneImageGrid); Button selectedImage = (Button) findViewById(R.id.selectBtn); imageAdapter = new ImageAdapter(); imagegrid.setAdapter(imageAdapter); selectedImage.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Toast.makeText(SampleActivity.this, "" + SampleActivity.this.selectedImage, 10).show();
} });
}
public class ImageAdapter extends BaseAdapter { private LayoutInflater mInflater;
public ImageAdapter() { mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); }
public Object getItem(int position) { return position; }
public long getItemId(int position) { return position; }
public View getView(int position, View convertView, ViewGroup parent) { ImageView imageview; CheckBox checkbox; convertView = mInflater.inflate(R.layout.mygallert, null); imageview = (ImageView) convertView.findViewById(R.id.thumbImage); checkbox = (CheckBox) convertView.findViewById(R.id.itemCheckBox); imageview.setBackgroundResource(R.drawable.icon); checkbox.setId(position); checkbox.setChecked(false); checkbox.setOnClickListener(new OnClickListener() { public void onClick(View v) { CheckBox cb = (CheckBox) v; if (cb.isChecked()) { cb.setChecked(true); selectedImage.add(v.getId()); } else { cb.setChecked(false); selectedImage.remove(v.getId()); } } }); return convertView; }
public int getCount() { return 5; } }
}
Required XMLmain.xml< ?xml version="1.0" encoding="utf-8"?>< RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> < Button android:id="@+id/selectBtn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Select" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:minWidth="200px" /> < GridView android:id="@+id/PhoneImageGrid" android:layout_width="fill_parent" android:layout_height="fill_parent" android:numColumns="auto_fit" android:verticalSpacing="10dp" android:horizontalSpacing="10dp" android:columnWidth="90dp" android:stretchMode="columnWidth" android:gravity="center" android:layout_above="@id/selectBtn" />< /RelativeLayout>
mygallery.xml< ?xml version="1.0" encoding="utf-8"?>< RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> < ImageView android:id="@+id/thumbImage" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" /> < CheckBox android:id="@+id/itemCheckBox" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_alignParentTop="true" />< /RelativeLayout>
1. Custom ViewComponet
< RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> < ImageView android:id="@+id/thumbImage" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" /> < CheckBox android:id="@+id/itemCheckBox" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_alignParentTop="true" /> < /RelativeLayout>
2. SampleActivity
1. Create a ImageAdapter public class ImageAdapter extends BaseAdapter { }
2. Inflate the View mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); convertView = mInflater.inflate(R.layout.mygallert, null); 3. find the required View imageview = (ImageView) convertView.findViewById(R.id.thumbImage); checkbox = (CheckBox) convertView.findViewById(R.id.itemCheckBox);
4. Control the image selection imageview.setBackgroundResource(R.drawable.icon); checkbox.setId(position); checkbox.setChecked(false); checkbox.setOnClickListener(new OnClickListener() { public void onClick(View v) { CheckBox cb = (CheckBox) v; if (cb.isChecked()) { cb.setChecked(true); selectedImage.add(v.getId()); } else { cb.setChecked(false); selectedImage.remove(v.getId()); } } });
4. Track the image selection selectedImage.add(v.getId()); selectedImage.remove(v.getId());
5. displays the selected Image Position Toast.makeText(SampleActivity.this,"" + SampleActivity.this.selectedImage, 10).show();
Sample
public class SampleActivity extends Activity { private ImageAdapter imageAdapter; private Set
/** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); GridView imagegrid = (GridView) findViewById(R.id.PhoneImageGrid); Button selectedImage = (Button) findViewById(R.id.selectBtn); imageAdapter = new ImageAdapter(); imagegrid.setAdapter(imageAdapter); selectedImage.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Toast.makeText(SampleActivity.this, "" + SampleActivity.this.selectedImage, 10).show();
} });
}
public class ImageAdapter extends BaseAdapter { private LayoutInflater mInflater;
public ImageAdapter() { mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); }
public Object getItem(int position) { return position; }
public long getItemId(int position) { return position; }
public View getView(int position, View convertView, ViewGroup parent) { ImageView imageview; CheckBox checkbox; convertView = mInflater.inflate(R.layout.mygallert, null); imageview = (ImageView) convertView.findViewById(R.id.thumbImage); checkbox = (CheckBox) convertView.findViewById(R.id.itemCheckBox); imageview.setBackgroundResource(R.drawable.icon); checkbox.setId(position); checkbox.setChecked(false); checkbox.setOnClickListener(new OnClickListener() { public void onClick(View v) { CheckBox cb = (CheckBox) v; if (cb.isChecked()) { cb.setChecked(true); selectedImage.add(v.getId()); } else { cb.setChecked(false); selectedImage.remove(v.getId()); } } }); return convertView; }
public int getCount() { return 5; } }
}
Required XMLmain.xml< ?xml version="1.0" encoding="utf-8"?>< RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> < Button android:id="@+id/selectBtn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Select" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:minWidth="200px" /> < GridView android:id="@+id/PhoneImageGrid" android:layout_width="fill_parent" android:layout_height="fill_parent" android:numColumns="auto_fit" android:verticalSpacing="10dp" android:horizontalSpacing="10dp" android:columnWidth="90dp" android:stretchMode="columnWidth" android:gravity="center" android:layout_above="@id/selectBtn" />< /RelativeLayout>
mygallery.xml< ?xml version="1.0" encoding="utf-8"?>< RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> < ImageView android:id="@+id/thumbImage" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" /> < CheckBox android:id="@+id/itemCheckBox" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_alignParentTop="true" />< /RelativeLayout>
Gesture based action
To contact us Click HERE
Here we are discussing about how to set that as the gesture listener for the views that I add.My requirement : I have list of images in a listview with url. When the user wants view the full image then user click the image on the list viewit will take to me the anonther activity and open in a imageview. and as a user wants to tee the next nexe or previous image with come back to listview page
Solution : I have created the HashMap Contains the list of images and pass the selected images name as bundle string. In a detail view created the async task the fetch image from the internetimplement the gestureListener. In this article we discussing about that
Related : gesture move action, gesture based action, example geatures
1. Create a Activity implements OnClickListener public class MySample1Activity extends Activity implements OnClickListener { ........ }2. Initialize below required object for gestureListener ViewConfiguration vc;
static int SWIPE_MAX_OFF_PATH = 250; static int SWIPE_MIN_DISTANCE = 100; static int SWIPE_THRESHOLD_VELOCITY = 100;
private GestureDetector gestureDetector; View.OnTouchListener gestureListener;
3. Set Densitybased velocity vc = ViewConfiguration.get(this); SWIPE_MIN_DISTANCE = vc.getScaledTouchSlop(); SWIPE_THRESHOLD_VELOCITY = vc.getScaledMinimumFlingVelocity();
4. Create a Custom GestureListener class which extends SimpleOnGestureListenerclass MyGestureDetector extends SimpleOnGestureListener {
}
5. Override the onFling() and implement the geature move action@Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { try { if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH) return false; // right to left swipe if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) { Toast.makeText(MySample1Activity.this, "Left Swipe", Toast.LENGTH_SHORT).show(); } else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) { Toast.makeText(MySample1Activity.this, "Right Swipe", Toast.LENGTH_SHORT).show(); } } catch (Exception e) { // nothing } return false; }
Full SourceCodepublic class MySample1Activity extends Activity implements OnClickListener { /** Called when the activity is first created. */ TextView tView;
ViewConfiguration vc;
static int SWIPE_MAX_OFF_PATH = 250; static int SWIPE_MIN_DISTANCE = 100; static int SWIPE_THRESHOLD_VELOCITY = 100;
private GestureDetector gestureDetector; View.OnTouchListener gestureListener;
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); tView = (TextView) findViewById(R.id.textview1); vc = ViewConfiguration.get(this); SWIPE_MIN_DISTANCE = vc.getScaledTouchSlop(); SWIPE_THRESHOLD_VELOCITY = vc.getScaledMinimumFlingVelocity();
gestureDetector = new GestureDetector(new MyGestureDetector()); gestureListener = new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { if (gestureDetector.onTouchEvent(event)) { return true; } return false; } }; tView.setOnClickListener(this); tView.setOnTouchListener(gestureListener); }
class MyGestureDetector extends SimpleOnGestureListener { @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { try { if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH) return false; // right to left swipe if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) { Toast.makeText(MySample1Activity.this, "Left Swipe", Toast.LENGTH_SHORT).show(); } else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) { Toast.makeText(MySample1Activity.this, "Right Swipe", Toast.LENGTH_SHORT).show(); } } catch (Exception e) { // nothing } return false; } }
@Override public void onClick(View v) { // TODO Auto-generated method stub
}
}
Solution : I have created the HashMap Contains the list of images and pass the selected images name as bundle string. In a detail view created the async task the fetch image from the internetimplement the gestureListener. In this article we discussing about that
Related : gesture move action, gesture based action, example geatures
1. Create a Activity implements OnClickListener public class MySample1Activity extends Activity implements OnClickListener { ........ }2. Initialize below required object for gestureListener ViewConfiguration vc;
static int SWIPE_MAX_OFF_PATH = 250; static int SWIPE_MIN_DISTANCE = 100; static int SWIPE_THRESHOLD_VELOCITY = 100;
private GestureDetector gestureDetector; View.OnTouchListener gestureListener;
3. Set Densitybased velocity vc = ViewConfiguration.get(this); SWIPE_MIN_DISTANCE = vc.getScaledTouchSlop(); SWIPE_THRESHOLD_VELOCITY = vc.getScaledMinimumFlingVelocity();
4. Create a Custom GestureListener class which extends SimpleOnGestureListenerclass MyGestureDetector extends SimpleOnGestureListener {
}
5. Override the onFling() and implement the geature move action@Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { try { if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH) return false; // right to left swipe if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) { Toast.makeText(MySample1Activity.this, "Left Swipe", Toast.LENGTH_SHORT).show(); } else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) { Toast.makeText(MySample1Activity.this, "Right Swipe", Toast.LENGTH_SHORT).show(); } } catch (Exception e) { // nothing } return false; }
Full SourceCodepublic class MySample1Activity extends Activity implements OnClickListener { /** Called when the activity is first created. */ TextView tView;
ViewConfiguration vc;
static int SWIPE_MAX_OFF_PATH = 250; static int SWIPE_MIN_DISTANCE = 100; static int SWIPE_THRESHOLD_VELOCITY = 100;
private GestureDetector gestureDetector; View.OnTouchListener gestureListener;
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); tView = (TextView) findViewById(R.id.textview1); vc = ViewConfiguration.get(this); SWIPE_MIN_DISTANCE = vc.getScaledTouchSlop(); SWIPE_THRESHOLD_VELOCITY = vc.getScaledMinimumFlingVelocity();
gestureDetector = new GestureDetector(new MyGestureDetector()); gestureListener = new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { if (gestureDetector.onTouchEvent(event)) { return true; } return false; } }; tView.setOnClickListener(this); tView.setOnTouchListener(gestureListener); }
class MyGestureDetector extends SimpleOnGestureListener { @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { try { if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH) return false; // right to left swipe if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) { Toast.makeText(MySample1Activity.this, "Left Swipe", Toast.LENGTH_SHORT).show(); } else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) { Toast.makeText(MySample1Activity.this, "Right Swipe", Toast.LENGTH_SHORT).show(); } } catch (Exception e) { // nothing } return false; } }
@Override public void onClick(View v) { // TODO Auto-generated method stub
}
}
Sample CheckedTextView in listview , Reading contacts all emails
To contact us Click HERE
Here, you can find the example of checked textview in the listview and read all email address in the android phone
1. Design the main Layout & row Layout with Checked TextView
Main.xml
< ListView android:id="@+id/listView1" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:background="#ffffff" />
Row.xml
< CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/checkedTextView1" android:paddingLeft="20dip"
android:paddingRight="20dip" android:paddingTop="10dip"
android:paddingBottom="10dip" android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="?android:attr/listPreferredItemHeight"
android:gravity="center_vertical" android:checkMark="@android:drawable/checkbox_off_background"
android:textColor="#000000" />
2. Create the CursurAdpater
private class ContactListAdapter extends CursorAdapter {
public ContactListAdapter(Context context, Cursor c) {
super(context, c);
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
String o = cursor
.getString(cursor
.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));
CheckedTextView tt = (CheckedTextView) view
.findViewById(R.id.checkedTextView1);
tt.setText(o);
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
View v;
LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.row, null);
return v;
}
}
3. set the Contact Cursor to the ContactListAdapter
ContentResolver cr = getContentResolver();
Cursor emails = cr.query(
ContactsContract.CommonDataKinds.Email.CONTENT_URI, null, null,
null, null);
l.setAdapter(new ContactListAdapter(this, emails));
4. Change the State while select the Item
l.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView arg0, View v, int arg2,
long arg3) {
CheckedTextView tt = (CheckedTextView) v
.findViewById(R.id.checkedTextView1);
if (!tt.isChecked()) {
tt.setChecked(true);
tt.setCheckMarkDrawable(android.R.drawable.checkbox_on_background);
} else {
tt.setChecked(false);
tt.setCheckMarkDrawable(android.R.drawable.checkbox_off_background);
}
}
});
5. Add the Contact Read Permission in androidmanifest.xml
< uses-permission android:name="android.permission.READ_CONTACTS" />
Sample Program :
public class ContactListingActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ListView l = (ListView) findViewById(R.id.listView1);
Cursor emails = getContentResolver().query(
ContactsContract.CommonDataKinds.Email.CONTENT_URI, null, null,
null, null);
l.setAdapter(new ContactListAdapter(this, emails));
l.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView arg0, View v, int arg2,
long arg3) {
CheckedTextView tt = (CheckedTextView) v
.findViewById(R.id.checkedTextView1);
if (!tt.isChecked()) {
tt.setChecked(true);
tt.setCheckMarkDrawable(android.R.drawable.checkbox_on_background);
} else {
tt.setChecked(false);
tt.setCheckMarkDrawable(android.R.drawable.checkbox_off_background);
}
}
});
}
private class ContactListAdapter extends CursorAdapter {
public ContactListAdapter(Context context, Cursor c) {
super(context, c);
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
String o = cursor
.getString(cursor
.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));
CheckedTextView tt = (CheckedTextView) view
.findViewById(R.id.checkedTextView1);
tt.setText(o);
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
View v;
LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.row, null);
return v;
}
}
}
1. Design the main Layout & row Layout with Checked TextView
Main.xml
< ListView android:id="@+id/listView1" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:background="#ffffff" />
Row.xml
< CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/checkedTextView1" android:paddingLeft="20dip"
android:paddingRight="20dip" android:paddingTop="10dip"
android:paddingBottom="10dip" android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="?android:attr/listPreferredItemHeight"
android:gravity="center_vertical" android:checkMark="@android:drawable/checkbox_off_background"
android:textColor="#000000" />
2. Create the CursurAdpater
private class ContactListAdapter extends CursorAdapter {
public ContactListAdapter(Context context, Cursor c) {
super(context, c);
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
String o = cursor
.getString(cursor
.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));
CheckedTextView tt = (CheckedTextView) view
.findViewById(R.id.checkedTextView1);
tt.setText(o);
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
View v;
LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.row, null);
return v;
}
}
3. set the Contact Cursor to the ContactListAdapter
ContentResolver cr = getContentResolver();
Cursor emails = cr.query(
ContactsContract.CommonDataKinds.Email.CONTENT_URI, null, null,
null, null);
l.setAdapter(new ContactListAdapter(this, emails));
4. Change the State while select the Item
l.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView arg0, View v, int arg2,
long arg3) {
CheckedTextView tt = (CheckedTextView) v
.findViewById(R.id.checkedTextView1);
if (!tt.isChecked()) {
tt.setChecked(true);
tt.setCheckMarkDrawable(android.R.drawable.checkbox_on_background);
} else {
tt.setChecked(false);
tt.setCheckMarkDrawable(android.R.drawable.checkbox_off_background);
}
}
});
5. Add the Contact Read Permission in androidmanifest.xml
< uses-permission android:name="android.permission.READ_CONTACTS" />
Sample Program :
public class ContactListingActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ListView l = (ListView) findViewById(R.id.listView1);
Cursor emails = getContentResolver().query(
ContactsContract.CommonDataKinds.Email.CONTENT_URI, null, null,
null, null);
l.setAdapter(new ContactListAdapter(this, emails));
l.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView arg0, View v, int arg2,
long arg3) {
CheckedTextView tt = (CheckedTextView) v
.findViewById(R.id.checkedTextView1);
if (!tt.isChecked()) {
tt.setChecked(true);
tt.setCheckMarkDrawable(android.R.drawable.checkbox_on_background);
} else {
tt.setChecked(false);
tt.setCheckMarkDrawable(android.R.drawable.checkbox_off_background);
}
}
});
}
private class ContactListAdapter extends CursorAdapter {
public ContactListAdapter(Context context, Cursor c) {
super(context, c);
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
String o = cursor
.getString(cursor
.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));
CheckedTextView tt = (CheckedTextView) view
.findViewById(R.id.checkedTextView1);
tt.setText(o);
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
View v;
LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.row, null);
return v;
}
}
}
Hide showed Toast Messages
To contact us Click HERE
In my App, there is a list, when a user clicks on an button, a toast message is being displayed, 10 items - 10 toast messages, so if the user clicks 10 times, then presses the button... he/she has to wait for some seconds, until he's able to read the menu option text.
I have found the below solution to hide the shows toast message.
public class SampleToastActivity extends Activity { Toast myToast; static int i=0; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button b1 = (Button) findViewById(R.id.button2); b1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { i++; if(myToast!=null){ myToast.cancel(); myToast.setText("Count"+i); }else{ myToast = Toast.makeText(SampleToastActivity.this, "Sample"+i, 10); } myToast.show(); } }); }}
I have found the below solution to hide the shows toast message.
public class SampleToastActivity extends Activity { Toast myToast; static int i=0; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button b1 = (Button) findViewById(R.id.button2); b1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { i++; if(myToast!=null){ myToast.cancel(); myToast.setText("Count"+i); }else{ myToast = Toast.makeText(SampleToastActivity.this, "Sample"+i, 10); } myToast.show(); } }); }}
Kaydol:
Yorumlar (Atom)