last day (14 days later) » 

2:07 PM
0
Q: concept of grid/list view how to send image to imageitem class

MoudizIn my project I want to load url Images and display them in gridview activity. but how to load those image to the gridview adapter? so I am trying to understand the concept of grid/list view adapter and as I understand .in a basic example ,it contain 3 activities: 1-Main activity Useally it c...

 
One should not use bitmap hard refrenced in object. You seem new to android. You can pass image url in ImageItem creating image url or id field. Now if images are from local resources you don't need picasso.
 
@subhash the above are just example , I am passing the iamge as url and I already stored the url in database but my problem if you can help me how to create a method that get the url from database and send to the picasso . I created such method but didnt work
 
So the problem is retriving url's from sqlite, creating ImageItem objects and passing them as array in adapter?
 
@subhash no i am using mysql , with asynctask , what I am doing is uploadign an image to server and store its url to database mysql , then in my mainactivity I am displayin the image as gridview. so I ma having trouble how to get this url and call them in the adapter
 
ok so where in following process you had problem? 1) Fetching data from server and creating list of ImageItem objects 2) Passing data to adapter 3) Consumption of data in adapter i.e displaying data
 
2:07 PM
@subhash well I was able to fetch the url from php with asynctask , but I had problem to send them to the adapter and display the image correctly .
 
hello
 
hello thanks for your support
 
so have you created arrayList of ImageItem objects in asyncTask?
 
is it ok if we start that from begining ? we do all the three steps ? or you prefer If i show you the code I created ? I want to see what is the right way to code it
 
ok give me the codes itll be fast
 
2:16 PM
ok give me 5 min ill provide it to you
you there ??
 
2:32 PM
protected void sendurl(){
try {
JSONObject jsonObj = new JSONObject(myJSON);
Dburl = jsonObj.getJSONArray(TAG_RESULTS);

for(int i=0;i<peoples.length();i++){
JSONObject c = Dburl.getJSONObject(i);
String id = c.getString(“ID”);
String url = c.getString(“URL”);


HashMap<String,String> vurl= new HashMap<String,String>();

vurl.put(“ID”,id);
vurl.put(“URL”,url);

Dburl.add(vurl);
}

ListAdapter adapter = new SimpleAdapter(
MainActivity.this, Dburl , R.layout.list,
new String[]{“ID”,”URL”},
new int[]{R.id.id, R.id.url }
 
it seems you lack basic understanding and are new which has made it more complex then it should be
Ill write basic steps which will be easier to understand
Create a simple ImageItem class like:
public class ImageItem {
private String id;
private String url;

public ImageItem(String id, String url) {
this.id = id;
this.url = url;
}

public String getId() {
return id;
}

public String getUrl() {
return url;
}
}
you there?
 
3:28 PM
Yes i am here please continur
This is setter getter class
 
yes this will help you avoid hasmaps etc and String arrays
I guess you are sure that response from server is correct right?
 
3:54 PM
Now create your getData method like
public void getData() {
class GetDataJSON extends AsyncTask<String, Void, List<ImageItem>> {

@Override
protected List<ImageItem> doInBackground(String... params) {
//...
//Your network code here which creates response data as string i.e result
String result = null; //Your json result from network
//Now create list of imageItems here
try {
JSONObject jsonObj = new JSONObject(result);
JSONArray Dburl = jsonObj.getJSONArray(TAG_RESULTS);

ArrayList<ImageItem> items = new ArrayList<>();
//I guess this peoples variable is you are doing on purpose
Change your adapter class like:
public class GridViewAdapter extends ArrayAdapter<ImageItem> {
private Context context;
private int layoutResourceId;

public GridViewAdapter(Context context, int layoutResourceId, ArrayList<ImageItem> data) {
super(context, layoutResourceId, data);
this.layoutResourceId = layoutResourceId;
this.context = context;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
ViewHolder holder;

if (row == null) {
LayoutInflater inflater = LayoutInflater.from(context);
and your activity oncreate method change to:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

gridView = (GridView) findViewById(R.id.gridView);
}
because we will create and instantiate adapter and set to gridview later
 
4:25 PM
Thanks so much for your explanation i will try it now please stay following up my chating
 

last day (14 days later) »