26/02/2016

Realm Using value Insert

Class Name : Sampledb.class
package com.main.android.databasemodels;
public class Sampledb extends RealmObject {
 @PrimaryKey
 private String id;
 private String name;
 public String getId() {
    return id;
}
 public void setId(String id) {
   this.id= id;
}
public String getName() {
    return name;
}
public void setName(String name) {
    this.name= name;
}
}
Class Name: Mainactivity
public class Mainactivity extends AppCompatActivity{
 Realm realm;
 @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sample);
    realm = Realm.getDefaultInstance();
    removeExamlisttable();
    realm.beginTransaction();
   for(int i=0;i<arraylistres.length();i++){
    //Create ExamList Realm Object    
Sampledb sampledb= realm.createObject(Sampledb.class);
    sampledb.setId(arraylistres.get(i).getId());
   sampledb.setName(arraylistres.get(i).getName());   }
  realm.commitTransaction();
 }
private void removeSampledbtable(){
    try {
        realm.beginTransaction();
        realm.clear(sampledb.class);
    }catch (Exception e){
        e.printStackTrace(); 
    }finally {
        realm.commitTransaction();
    }
} 
// Find All value 
Sampledb sampledb=realm.where(Sampledb.class).findAll);
}

06/01/2016

Listview Using Custom Adapter

public class Mainactivity extends FragmentActivity{
      private ArrayList<Places> list = new ArrayList<Places>();
      private PlaceListAdapter mPlaceListAdapter;
private ListView placelistview;
       @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.nearbydreserlistview_layout);
               placelistview = (ListView)findViewById(R.id.placelistview);
              list.add(new Places("a"));
              list.add(new Places("b"));
              list.add(new Places("c"));
              list.add(new Places("d"));
              mPlaceListAdapter = new PlaceListAdapter(context, list);
    placelistview.setAdapter(mPlaceListAdapter);
       }
      public class PlaceListAdapter extends BaseAdapter {
private Context mContext;
private ArrayList<Places> mplaceList;
private LayoutInflater mLayoutInflater = null;

public PlaceListAdapter(Context context, ArrayList<Places> list) {
mContext = context;
mplaceList = list;
mLayoutInflater = (LayoutInflater)            mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
return mplaceList.size();
}
@Override
public Object getItem(int pos) {
return mplaceList.get(pos);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
try {
final ListViewHolder viewHolder;
if (convertView == null) {
LayoutInflater li = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = li.inflate(R.layout.placelistadapter_layout, parent,false);
viewHolder = new ListViewHolder(convertView);
convertView.setTag(viewHolder);
} else {
viewHolder = (ListViewHolder) convertView.getTag();
}
viewHolder.name.setText(mplaceList.get(position).getName());
} catch (Exception e) {
e.printStackTrace();
}
return convertView;
}
}
class ListViewHolder {
   public TextView name;
   public ListViewHolder(View base){
    super();
    try {
    name= (TextView) base.findViewById(R.id.txt_name);
    }catch(Exception e){e.printStackTrace();}
   }
}
}