Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8975441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:52:52+00:00 2026-06-15T18:52:52+00:00

i want to create a dynamic GridView, and when i click to my options

  • 0

i want to create a dynamic GridView, and when i click to my options meny, i refresh my asyncTask, then i get all result’s from postExecute, and notify my adapter to refresh! But i doesn’t work HELP me please!

GridView grid;
ImageAdapter adapter;

ArrayList<String> arrayThumbs = new ArrayList<String>();
ArrayList<String> arrayBig_image = new ArrayList<String>();
ArrayList<String> arrayAuthor = new ArrayList<String>();
ArrayList<String> arrayDescription = new ArrayList<String>();
ArrayList<String> arrayDate = new ArrayList<String>();

String[] arraymThumbs;
String[] arrayBimages;
String[] arrayauthor;
String[] arraydescription;
String[] arraydate;

final static String TAG_ITEM = "img_list";
final static String TAG_THUMBNAILS = "thumbnail";
final static String TAG_BIG_IMAGE = "big_image";
final static String TAG_AUTHOR = "author";
final static String TAG_DESCRIPTION = "description";
final static String TAG_DATE = "event_date";

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

        backTask();


        grid = (GridView) findViewById(R.id.grid);
        grid.setAdapter(adapter);
        grid.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> adapterview, View view,  int position, long id) {
                Intent intent = new Intent(MainActivity.this, ImageGallery.class);
                intent.putExtra("position", position);
                intent.putExtra("big_images", arrayBimages);
                intent.putExtra("author", arrayauthor);
                intent.putExtra("description", arraydescription);
                intent.putExtra("date", arraydate);
                startActivity(intent);
            }
        }); 

}

public boolean onCreateOptionsMenu(Menu menu){
    getMenuInflater().inflate(R.menu.main, menu);
    return super.onCreateOptionsMenu(menu);

}

public boolean onOptionsItemSelected(MenuItem item){        
    switch (item.getItemId()) {
    case R.id.refresh:
        backTask();
        break;
    }
    return super.onOptionsItemSelected(item);
}

public void backTask(){

    BackTask task = new BackTask();
    task.execute();



    try {
        JSONObject result = task.get();
        if(result != null){
        JSONArray jarray = result.getJSONArray(TAG_ITEM);
        for(int i = 0; i < jarray.length(); i++){
            JSONObject jrss = jarray.getJSONObject(i);
            arrayThumbs.add(jrss.getString(TAG_THUMBNAILS));
            arrayBig_image.add(jrss.getString(TAG_BIG_IMAGE));
            arrayAuthor.add(jrss.getString(TAG_AUTHOR));
            arrayDescription.add(jrss.getString(TAG_DESCRIPTION));
            arrayDate.add(jrss.getString(TAG_DATE));

            Log.d("LLLLLOOOOGGGG", jrss.getString("author")+"\n");
        }}
        else{
            AlertDialog.Builder alertNetworkError = new AlertDialog.Builder(this);
            alertNetworkError.setMessage("нет подключения к интернету");
            alertNetworkError.setNegativeButton("Выйти", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    finish();                           
                }                       
            });
            alertNetworkError.create();
            alertNetworkError.show();
        }
    } catch (InterruptedException e) {
        e.printStackTrace();
    } catch (ExecutionException e) {
        e.printStackTrace();
    } catch (JSONException e) {
        e.printStackTrace();
    }

    arraymThumbs = new String[arrayThumbs.size()];
    arraymThumbs = arrayThumbs.toArray(arraymThumbs);

    arrayBimages = new String[arrayBig_image.size()];
    arrayBimages = arrayBig_image.toArray(arrayBimages);

    arrayauthor = new String[arrayAuthor.size()];
    arrayauthor = arrayAuthor.toArray(arrayauthor);

    arraydescription = new String[arrayDescription.size()];
    arraydescription = arrayDescription.toArray(arraydescription);

    arraydate = new String[arrayDate.size()];
    arraydate = arrayDate.toArray(arraydate);
    adapter = new ImageAdapter(MainActivity.this, arraymThumbs);
    adapter.notifyDataSetChanged();



}

And my image adapter here i get all result’s from asyncTask and print thumbs images to my GridView

public class ImageAdapter extends BaseAdapter {

    public Context mContext;
    String[] mThumbs;
    public LayoutInflater inflater;
    public DisplayImageOptions options;
    public ImageLoader imageLoader;


    public ImageAdapter (Context c, String[] arrayhumbss){
        mContext = c;
        inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        mThumbs = arrayhumbss;
        options  = new DisplayImageOptions.Builder()
                .showStubImage(R.drawable.ic_contact_picture_2)
                .showImageForEmptyUri(R.drawable.ic_launcher)
                .cacheInMemory()
                .cacheOnDisc()
                .bitmapConfig(Bitmap.Config.RGB_565)
                .build();
        imageLoader = ImageLoader.getInstance();
        imageLoader.init(ImageLoaderConfiguration.createDefault(c));
    }


    @Override
    public int getCount() {
        return mThumbs.length;
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {     
        final ImageView imageView;
        if (convertView == null) {
            imageView = (ImageView) inflater.inflate(R.layout.grid_item, parent, false);
        } else {
            imageView = (ImageView) convertView;
        }

        imageLoader.displayImage(mThumbs[position], imageView, options);

        return imageView;
    }



}

This is my BACKTASK

public class BackTask extends AsyncTask<String, Void, JSONObject>{  

@Override
protected JSONObject doInBackground(String... params) {
    InputStream ips = null; 
    JSONObject jsonObj = null;
    String json = "";       
    try {
        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpResponse response = httpClient.execute(new HttpPost("http://192.168.1.179/lenta/image.js"));                
        ips = response.getEntity().getContent();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    try {
        BufferedReader bufff = new BufferedReader(new InputStreamReader(ips, "UTF-8"));
        StringBuilder sb = new StringBuilder();
        String line = null;

        while ((line = bufff.readLine()) != null){
            sb.append(line + "\n");                 
        }
        ips.close();
        json = sb.toString();       
    } catch (Exception e) {
        e.printStackTrace();
    }

    try {
        jsonObj = new JSONObject(json);
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return jsonObj;     

    }

    @Override
    protected void onPostExecute(JSONObject result){
        super.onPostExecute(result);



        }

}

here i handle my json from url, and in MainActivity i get this form task.get()

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T18:52:53+00:00Added an answer on June 15, 2026 at 6:52 pm

    Add grid.setAdapter(adapter) right after this line

     adapter = new ImageAdapter(MainActivity.this, arraymThumbs);
    

    Hope this would solve your problem.

    EDIT: P.S. It seems you need to read something, because i think you don’t fully understand what adapter is and how to use it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have create dynamic datepicker inside gridview. i want to know how to get
I want to create a dynamic menu that will get it's items from a
I want to create a dynamic object in Python and then add attributes to
I want to create a dynamic select input (dropdown menu) from JSON. I have
I want to create a dynamic Accordion, My usecase is like, On every click
I want create MenuStrip dynamic (in winform C#.Net 4.0) From Database (SQL Server) and
I want to create dynamic menu from Database it's mean i have Catagory is
I want to create dynamic buttons on button click event(for example., btnCreateDynamic_Click). I tried
I want to create an Observable Array from a Dynamic Model that is basically
I want to create a dynamic alert from a specific input value within each

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.