dimanche 1 mars 2015

How to make user add images to drawable from system?

I'm facing a problem. I'm using an Image GridView of stuff, and I created an object and all. I want to make the user, by tapping a button, to add an image to resources, and then I want to even be able to use that image ID so i can add it to my objects and gridview.


This is my activity: (the part that is needed)



public class ImageAdapter extends BaseAdapter {
private Context mContext;

public ImageAdapter(Context c) {
mContext = c;
}

public int getCount() {
return mThumbIds.size();
}

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) {
View grid;
LayoutInflater inflater = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
grid = new View(mContext);
grid = inflater.inflate(R.layout.grid_single, null);
ImageView imageView = (ImageView)grid.findViewById(R.id.grid_image);
TextView textView = (TextView) grid.findViewById(R.id.grid_text);
imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
textView.setText(mThumbIds.get(position).getDesc());
imageView.setImageResource(mThumbIds.get(position).getImageID());
} else {
grid = (View) convertView;
}
return grid;
}
}

public void createAll(){
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
parentGender = prefs.getString("parentGender", "1");
parentNum = prefs.getString("parentNum", "");
childName = prefs.getString("childName", "Kiddo");
final String opening=parentGender+", "+childName;
if(mThumbIds.size()==0){
mThumbIds.add(tv);
mThumbIds.add(cookie);
mThumbIds.add(toilet);
mThumbIds.add(toys);
mThumbIds.add(food);
mThumbIds.add(water);
}
final GridView gridview = (GridView) findViewById(R.id.grid);
gridview.setAdapter(new ImageAdapter(this));


gridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {


public void onItemClick(AdapterView<?> parent, View v, final int position, long id) {


blah blah blah.....(from now on its the handling of a click on item)


NOTE::: mThumbIds is an ArrayList<E> E> of my object which contains a title and an image ID!


How do i make a user add an image and use its id??


Aucun commentaire:

Enregistrer un commentaire