public class Check extends Activity {
// List <String> ImageList;
ArrayList<ParserCategory>mList;
DatabaseConnectionAPI mApi;
ImageAdapter mAdapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/*** Get Images from SDCard ***/
// ImageList = getSD();
// gridView1
mApi=new DatabaseConnectionAPI(getApplicationContext());
try {
mApi.createDataBase();
mApi.openDataBase();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mList=mApi.getCategoryData();
final GridView gView1 = (GridView)findViewById(R.id.gridView1);
mAdapter=new ImageAdapter(Check.this, mList);
gView1.setAdapter(mAdapter);
// Check All
Button btnCheckAll = (Button) findViewById(R.id.btnCheckAll);
btnCheckAll.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
int count = gView1.getAdapter().getCount();
for (int i = 0; i < count; i++) {
LinearLayout itemLayout = (LinearLayout)gView1.getChildAt(i); // Find by under LinearLayout
CheckBox checkbox = (CheckBox)itemLayout.findViewById(R.id.checkBox1);
checkbox.setChecked(true);
}
}
});
// Clear All
Button btnClearAll = (Button) findViewById(R.id.btnClearAll);
btnClearAll.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
int count = gView1.getAdapter().getCount();
for (int i = 0; i < count; i++) {
LinearLayout itemLayout = (LinearLayout)gView1.getChildAt(i); // Find by under LinearLayout
CheckBox checkbox = (CheckBox)itemLayout.findViewById(R.id.checkBox1);
checkbox.setChecked(false);
}
}
});
// Get Item Checked
Button btnGetItem = (Button) findViewById(R.id.btnGetItem);
btnGetItem.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// int count = gView1.getAdapter().getCount();
int count = gView1.getChildCount();
System.out.println("Count "+count);
for (int i = 0; i < count; i++) {
ViewGroup gridChild = (ViewGroup) gView1.getChildAt(i);
// LinearLayout itemLayout = (LinearLayout)gView1.getChildAt(i); // Find by under LinearLayout
// System.out.println("itemLayout "+itemLayout);
CheckBox checkbox = (CheckBox)gridChild.findViewById(R.id.checkBox1);
if(checkbox.isChecked())
{
Log.d("Item "+String.valueOf(i), checkbox.getTag().toString());
System.out.println("ITEEMERM "+String.valueOf(i)+checkbox.getTag().toString());
Toast.makeText(Check.this,checkbox.getTag().toString() ,2000).show();
}
}
}
});
}
// private List <String> getSD()
// {
// List <String> it = new ArrayList <String>();
// File f = new File ("/mnt/sdcard/picture");
// File[] files = f.listFiles ();
//
// for (int i = 0; i <files.length; i++)
// {
// File file = files[i];
// Log.d("Count",file.getPath());
// it.add (file.getPath());
// }
// return it;
// }
public class ImageAdapter extends BaseAdapter
{
private Context context;
private ArrayList<ParserCategory> lis;
public ImageAdapter(Context c, ArrayList<ParserCategory> mList)
{
//
context = c;
lis = mList;
}
public int getCount() {
//
return lis.size();
}
public Object getItem(int position) {
//
return position;
}
public long getItemId(int position) {
//
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
//
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = inflater.inflate(R.layout.showimage, null);
}
TextView textView = (TextView) convertView.findViewById(R.id.textView1);
String strPath = lis.get(position).toString();
// Get File Name
String fileName=lis.get(position).getCname();
// String fileName = strPath.substring( strPath.lastIndexOf('/')+1, strPath.length() );
textView.setText(lis.get(position).getCname());
// Image Resource
ImageView imageView = (ImageView) convertView.findViewById(R.id.imageView1);
// CheckBox
CheckBox Chkbox = (CheckBox) convertView.findViewById(R.id.checkBox1);
Chkbox.setTag(fileName);
return convertView;
}
}
}
// List <String> ImageList;
ArrayList<ParserCategory>mList;
DatabaseConnectionAPI mApi;
ImageAdapter mAdapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/*** Get Images from SDCard ***/
// ImageList = getSD();
// gridView1
mApi=new DatabaseConnectionAPI(getApplicationContext());
try {
mApi.createDataBase();
mApi.openDataBase();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mList=mApi.getCategoryData();
final GridView gView1 = (GridView)findViewById(R.id.gridView1);
mAdapter=new ImageAdapter(Check.this, mList);
gView1.setAdapter(mAdapter);
// Check All
Button btnCheckAll = (Button) findViewById(R.id.btnCheckAll);
btnCheckAll.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
int count = gView1.getAdapter().getCount();
for (int i = 0; i < count; i++) {
LinearLayout itemLayout = (LinearLayout)gView1.getChildAt(i); // Find by under LinearLayout
CheckBox checkbox = (CheckBox)itemLayout.findViewById(R.id.checkBox1);
checkbox.setChecked(true);
}
}
});
// Clear All
Button btnClearAll = (Button) findViewById(R.id.btnClearAll);
btnClearAll.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
int count = gView1.getAdapter().getCount();
for (int i = 0; i < count; i++) {
LinearLayout itemLayout = (LinearLayout)gView1.getChildAt(i); // Find by under LinearLayout
CheckBox checkbox = (CheckBox)itemLayout.findViewById(R.id.checkBox1);
checkbox.setChecked(false);
}
}
});
// Get Item Checked
Button btnGetItem = (Button) findViewById(R.id.btnGetItem);
btnGetItem.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// int count = gView1.getAdapter().getCount();
int count = gView1.getChildCount();
System.out.println("Count "+count);
for (int i = 0; i < count; i++) {
ViewGroup gridChild = (ViewGroup) gView1.getChildAt(i);
// LinearLayout itemLayout = (LinearLayout)gView1.getChildAt(i); // Find by under LinearLayout
// System.out.println("itemLayout "+itemLayout);
CheckBox checkbox = (CheckBox)gridChild.findViewById(R.id.checkBox1);
if(checkbox.isChecked())
{
Log.d("Item "+String.valueOf(i), checkbox.getTag().toString());
System.out.println("ITEEMERM "+String.valueOf(i)+checkbox.getTag().toString());
Toast.makeText(Check.this,checkbox.getTag().toString() ,2000).show();
}
}
}
});
}
// private List <String> getSD()
// {
// List <String> it = new ArrayList <String>();
// File f = new File ("/mnt/sdcard/picture");
// File[] files = f.listFiles ();
//
// for (int i = 0; i <files.length; i++)
// {
// File file = files[i];
// Log.d("Count",file.getPath());
// it.add (file.getPath());
// }
// return it;
// }
public class ImageAdapter extends BaseAdapter
{
private Context context;
private ArrayList<ParserCategory> lis;
public ImageAdapter(Context c, ArrayList<ParserCategory> mList)
{
//
context = c;
lis = mList;
}
public int getCount() {
//
return lis.size();
}
public Object getItem(int position) {
//
return position;
}
public long getItemId(int position) {
//
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
//
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = inflater.inflate(R.layout.showimage, null);
}
TextView textView = (TextView) convertView.findViewById(R.id.textView1);
String strPath = lis.get(position).toString();
// Get File Name
String fileName=lis.get(position).getCname();
// String fileName = strPath.substring( strPath.lastIndexOf('/')+1, strPath.length() );
textView.setText(lis.get(position).getCname());
// Image Resource
ImageView imageView = (ImageView) convertView.findViewById(R.id.imageView1);
// CheckBox
CheckBox Chkbox = (CheckBox) convertView.findViewById(R.id.checkBox1);
Chkbox.setTag(fileName);
return convertView;
}
}
}
this code is not working for specific folder once rectify the problem....
ReplyDeleteit is very urgent requirement for me
THanks & Regards
siva