Search Results

Search found 5 results on 1 pages for 'customadapter'.

Page 1/1 | 1 

  • LazyTable Listview in Android?

    - by Praveen Chandrasekaran
    how to achieve the lazy table concepts which is in iphone. that is the listview with the custom adapter that contains imageview as icon and textview as three rows. when scroll the listview it stacked up to scroll. i want to make it easy. the image content should load only the visible part of the list view. how to do that? Any Idea?

    Read the article

  • Android - Custom Adapter Problem

    - by Ryan
    Hello, I seem to be having a problem with my Custom Adapter view. When I display the list, it only displays a white screen. Here is how it works: 1.) I send a JSON request 2.) populate the ArrayList with the returned results 3.) create a custom adapter 4.) then bind the adapter. Here is steps 2-4 private void updateUI() { ListView myList = (ListView) findViewById(android.R.id.list); itemList = new ArrayList(); Iterator it = data.entrySet().iterator(); while (it.hasNext()) { //Get the key name and value for it Map.Entry pair = (Map.Entry)it.next(); String keyName = (String) pair.getKey(); String value = pair.getValue().toString(); if (value != null) { ListItem li = new ListItem(keyName, value, false); itemList.add(li); } } CustomAdapter mAdapter = new CustomAdapter( mContext, itemList); myList.setAdapter(mAdapter); //Bind the adapter to the list //Tell the dialog it's cool now. dismissDialog(0); //Show next screen flipper.setInAnimation(inFromRightAnimation()); flipper.setOutAnimation(outToRightAnimation()); flipper.showNext(); } And here is my CustomAdapter class: import java.util.List; import android.R.color; import android.content.Context; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.ImageView; import android.widget.RelativeLayout; import android.widget.TextView; class MyAdapterView extends RelativeLayout { public MyAdapterView(Context c, ListItem li) { super( c ); RelativeLayout rL = new RelativeLayout(c); RelativeLayout.LayoutParams containerParams = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT); rL.setLayoutParams(containerParams); rL.setBackgroundColor(color.white); ImageView img = new ImageView (c); img.setImageResource(li.getImage()); img.setPadding(5, 5, 10, 5); rL.addView(img, 48, 48); TextView top = new TextView(c); top.setText(li.getTopText()); top.setTextColor(color.black); top.setTextSize(20); top.setPadding(0, 20, 0, 0); rL.addView(top,ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); TextView bot = new TextView( c ); bot.setText(li.getBottomText()); bot.setTextColor(color.black); bot.setTextSize(12); bot.setPadding(0, 0, 0, 10); bot.setAutoLinkMask(1); rL.addView(bot,ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); } } public class CustomAdapter extends BaseAdapter { private Context context; private List itemList; public CustomAdapter(Context c, List itemL ) { this.context = c; this.itemList = itemL; } public int getCount() { return itemList.size(); } public Object getItem(int position) { return itemList.get(position); } public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { ListItem li = itemList.get(position); return new MyAdapterView(this.context, li); } } Does anyone have any idea why this displays a white screen upon completion?? Thanks in advance!

    Read the article

  • [Android] Show default selection color for custom listview

    - by Diego
    Hello, I have a listview with a custom BaseAdapter. Each row of the listview has a TextView and a CheckBox. The problem is when I click (or touch) any row, the textview foreground becomes gray, instead of the default behavior (background - green, textview foreground - white). Here is the code: row.xml: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" style="@style/layout"> <TextView android:id="@+id/main_lv_item_textView" style="@style/textViewBig" android:layout_alignParentLeft="true"/> <CheckBox android:id="@+id/main_lv_item_checkBox" style="@style/checkBox" android:layout_width="wrap_content" android:layout_alignParentRight="true"/> </RelativeLayout> Custom Adapter: public class CustomAdapter extends BaseAdapter { private List<Profile> profiles; private LayoutInflater inflater; private TextView tvName; private CheckBox cbEnabled; public CustomAdapter(List<Profile> profiles) { this.profiles = profiles; inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); } public int getCount() { return profiles.size(); } public Object getItem(int position) { return profiles.get(position); } public long getItemId(int position) { return position; } public View getView(final int position, View convertView, ViewGroup parent) { View row = inflater.inflate(R.layout.main_lv_item, null); final Profile profile = profiles.get(position); tvName = (TextView) row.findViewById(R.id.main_lv_item_textView); registerForContextMenu(tvName); cbEnabled = (CheckBox) row.findViewById(R.id.main_lv_item_checkBox); tvName.setText(profile.getName()); if (profile.isEnabled()) { cbEnabled.setChecked(true); } tvName.setOnClickListener(new OnClickListener() { public void onClick(View v) { Bundle bundle = new Bundle(); bundle.putString(PROFILE_NAME_KEY, profile.getName()); Intent intent = new Intent(context, GuiProfile.class); intent.putExtras(bundle); startActivity(intent); } }); tvName.setOnLongClickListener(new OnLongClickListener() { public boolean onLongClick(View v) { selectedProfileName = ((TextView) v).getText().toString(); return false; } }); cbEnabled.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (!profile.isEnabled()) { for (Profile profile : profiles) { if (profile.isEnabled()) { profile.setEnabled(false); Database.getInstance().storeProfile(profile); } } } profile.setEnabled(isChecked); Database.getInstance().storeProfile(profile); updateListView(); } }); return row; } } Any help would be appreciated.

    Read the article

  • Saving image from Gallery to db - Coursor IllegalStateException

    - by MyWay
    I want to save to db some strings with image. Image can be taken from gallery or user can set the sample one. In the other activity I have a listview which should present the rows with image and name. I'm facing so long this problem. It occurs when I wanna display listview with the image from gallery, If the sample image is saved in the row everything works ok. My problem is similar to this one: how to save image taken from camera and show it to listview - crashes with "IllegalStateException" but I can't find there the solution for me My table in db looks like this: public static final String KEY_ID = "_id"; public static final String ID_DETAILS = "INTEGER PRIMARY KEY AUTOINCREMENT"; public static final int ID_COLUMN = 0; public static final String KEY_NAME = "name"; public static final String NAME_DETAILS = "TEXT NOT NULL"; public static final int NAME_COLUMN = 1; public static final String KEY_DESCRIPTION = "description"; public static final String DESCRIPTION_DETAILS = "TEXT"; public static final int DESCRIPTION_COLUMN = 2; public static final String KEY_IMAGE ="image" ; public static final String IMAGE_DETAILS = "BLOP"; public static final int IMAGE_COLUMN = 3; //method which create our table private static final String CREATE_PRODUCTLIST_IN_DB = "CREATE TABLE " + DB_TABLE + "( " + KEY_ID + " " + ID_DETAILS + ", " + KEY_NAME + " " + NAME_DETAILS + ", " + KEY_DESCRIPTION + " " + DESCRIPTION_DETAILS + ", " + KEY_IMAGE +" " + IMAGE_DETAILS + ");"; inserting statement: public long insertToProductList(String name, String description, byte[] image) { ContentValues value = new ContentValues(); // get the id of column and value value.put(KEY_NAME, name); value.put(KEY_DESCRIPTION, description); value.put(KEY_IMAGE, image); // put into db return db.insert(DB_TABLE, null, value); } Button which add the picture and onActivityResult method which saves the image and put it into the imageview public void AddPicture(View v) { // creating specified intent which have to get data Intent intent = new Intent(Intent.ACTION_PICK); // From where we want choose our pictures intent.setType("image/*"); startActivityForResult(intent, PICK_IMAGE); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { // TODO Auto-generated method stub super.onActivityResult(requestCode, resultCode, data); // if identification code match to the intent, //if yes we know that is our picture, if(requestCode ==PICK_IMAGE ) { // check if the data comes with intent if(data!= null) { Uri chosenImage = data.getData(); String[] filePathColumn = {MediaStore.Images.Media.DATA}; Cursor cursor = getContentResolver().query(chosenImage, filePathColumn, null, null, null); cursor.moveToFirst(); int columnIndex = cursor.getColumnIndex(filePathColumn[0]); String filePat = cursor.getString(columnIndex); cursor.close(); ImageOfProduct = BitmapFactory.decodeFile(filePat); if(ImageOfProduct!=null) { picture.setImageBitmap(ImageOfProduct); } messageDisplayer("got picture, isn't null " + IdOfPicture); } } } Then the code which converts bitmap to byte[] public byte[] bitmapToByteConvert(Bitmap bit ) { // stream of data getted for compressed bitmap ByteArrayOutputStream gettedData = new ByteArrayOutputStream(); // compressing method bit.compress(CompressFormat.PNG, 0, gettedData); // our byte array return gettedData.toByteArray(); } The method which put data to the row: byte[] image=null; // if the name isn't put to the editView if(name.getText().toString().trim().length()== 0) { messageDisplayer("At least you need to type name of product if you want add it to the DB "); } else{ String desc = description.getText().toString(); if(description.getText().toString().trim().length()==0) { messageDisplayer("the description is set as none"); desc = "none"; } DB.open(); if(ImageOfProduct!= null){ image = bitmapToByteConvert(ImageOfProduct); messageDisplayer("image isn't null"); } else { BitmapDrawable drawable = (BitmapDrawable) picture.getDrawable(); image = bitmapToByteConvert(drawable.getBitmap()); } if(image.length>0 && image!=null) { messageDisplayer(Integer.toString(image.length)); } DB.insertToProductList(name.getText().toString(), desc, image ); DB.close(); messageDisplayer("well done you add the product"); finish(); You can see that I'm checking here the length of array to be sure that I don't send empty one. And here is the place where Error appears imo, this code is from activity which presents the listview with data taken from db private void LoadOurLayoutListWithInfo() { // firstly wee need to open connection with db db= new sqliteDB(getApplicationContext()); db.open(); // creating our custom adaprer, the specification of it will be typed // in our own class (MyArrayAdapter) which will be created below ArrayAdapter<ProductFromTable> customAdapter = new MyArrayAdapter(); //get the info from whole table tablecursor = db.getAllColumns(); if(tablecursor != null) { startManagingCursor(tablecursor); tablecursor.moveToFirst(); } // now we moving all info from tablecursor to ourlist if(tablecursor != null && tablecursor.moveToFirst()) { do{ // taking info from row in table int id = tablecursor.getInt(sqliteDB.ID_COLUMN); String name= tablecursor.getString(sqliteDB.NAME_COLUMN); String description= tablecursor.getString(sqliteDB.DESCRIPTION_COLUMN); byte[] image= tablecursor.getBlob(3); tablefromDB.add(new ProductFromTable(id,name,description,image)); // moving until we didn't find last row }while(tablecursor.moveToNext()); } listView = (ListView) findViewById(R.id.tagwriter_listoftags); //as description says // setAdapter = The ListAdapter which is responsible for maintaining //the data backing this list and for producing a view to represent //an item in that data set. listView.setAdapter(customAdapter); } I put the info from row tho objects which are stored in list. I read tones of question but I can't find any solution for me. Everything works when I put the sample image ( which is stored in app res folder ). Thx for any advice

    Read the article

  • Android GridView Custom BaseAdapter ImageView ImageButton OnItemClick doesn´t work

    - by Marek
    i have a problem using a GridView with a CustomAdapter (extends BaseAdapter). any Activity implements the OnItemClickListener. if i use ImageView as item everything works fine, OnItemClick-Events will be fired/catched I have not found a useful example for a GridView with a custom BaseAdapter using ImageButton. Has anyone an idea? Many thanks in advantage! Snippets: class MyActivity extends Activity implements OnItemClickListener { ... @Override public void onCreate() { ... GridView gridview = (GridView) findViewById(R.id.gridview); gridview.setOnItemClickListener(this); gridview.setAdapter(new ImageButtonAdapter(this)); } ... @Override public void onItemClick(AdapterView<?> adapter, View view, int arg2, long arg3) { Log.e("onItemClick()", "arg2=" + arg2 + ", arg3=" + arg3); } } public class ImageButtonAdapter extends BaseAdapter { private Context mContext; public LayoutMenuAdapter(Context c) { mContext = c; } public int getCount() { return mThumbIds.length; } public Object getItem(int position) { return null; } public long getItemId(int position) { return 0; } public View getView(int position, View convertView, ViewGroup parent) { /* IF I USE THIS PART EVERYTHING WORKS FINE */ // ImageView imageView; // if (convertView == null) { // imageView = new ImageView(mContext); // imageView.setLayoutParams(new GridView.LayoutParams(100, 100)); // imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); // imageView.setPadding(0, 0, 0, 0); // imageView.setFocusable(false); // } else { // imageView = (ImageView) convertView; // } // imageView.setImageResource(mThumbIds[position]); // return imageView; /* IF I USE THIS PART NO THE ACTIVITY/LISTENER RECEIVES NO EVENT */ ImageButton imageButton; if (convertView == null) { imageButton = new ImageButton(mContext); imageButton.setLayoutParams(new GridView.LayoutParams(100, 100)); imageButton.setScaleType(ImageView.ScaleType.CENTER_CROP); imageButton.setPadding(0, 0, 0, 0); imageButton.setFocusable(false); } else { imageButton = (ImageButton) convertView; } imageButton.setImageResource(mThumbIds[position]); return imageButton; } // references to images private Integer[] mThumbIds = { R.drawable.media}; }

    Read the article

1