我想logcat所有动作菜单项

时间:2015-07-14 03:18:21

标签: android android-logcat action-menu

这是我的代码

Image_List.java

package com.prgguru.example;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.apache.http.NameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.ListView;
import android.widget.Toast;

public class Image_List extends Activity {
    ListView lv;
    JSONObject json_data;

    String username;

    JSONParser jParser = new JSONParser();

    ArrayList<HashMap<String, String>> memberList;
    ArrayList<HashMap<String, String>> imageList;

    String TAG_SUKSES = "sukses";
    String TAG_MEMBER = "member";
    String TAG_IMAGE_NAME = "image_name";
    String TAG_IMAGE_TOTAL_LIKE = "image_total_like";
    String TAG_IMAGE_SENDER_USERNAME = "image_sender_username";
    String TAG_IMAGE_ID = "image_id";
    String TAG_IMAGE_TITLE = "image_title";
    String TAG_IMAGE_SPECIES = "image_species";

    JSONArray member;

    @SuppressWarnings("rawtypes")
    ArrayList prgmName;
    public static String[] image_id;
    public static String[] image_name;
    public static String[] image_total_like;
    public static String[] image_sender_username;
    public static String[] image_title;
    public static String[] image_species;

    // ArrayList<String> iName = new ArrayList<String>();
    // ArrayList<String> iSenderId = new ArrayList<String>();
    // ArrayList<String> iSenderName = new ArrayList<String>();

    public static final int MENU_ADD = Menu.FIRST;
    public static final int MENU_DELETE = Menu.FIRST + 1;
    public static final int upload = Menu.FIRST + 2;
    public static final int search = Menu.FIRST + 3;
    public static final int map = Menu.FIRST + 4;
    public static final int setting = Menu.FIRST + 5;

    private Menu optionsMenu;

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

        // if you want your array

        Intent intent = getIntent();
        username = intent.getStringExtra("username");

        Toast.makeText(getApplicationContext(), "username:" + username,
                Toast.LENGTH_LONG).show();

        new AmbilData().execute();

    }

    @Override
    public void onBackPressed() {
        return;
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        this.optionsMenu = menu;
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.main, menu);

        menu.add(Menu.NONE, upload, Menu.NONE, "Upload Image with Camera");
        menu.add(Menu.NONE, search, Menu.NONE, "Search Image by Species Name");
        menu.add(Menu.NONE, map, Menu.NONE, "Show Image on Map");
        menu.add(Menu.NONE, setting, Menu.NONE, "Setting");

        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        Intent intent = new Intent();
        switch (item.getItemId()) {
        case R.id.airport_menuRefresh:
            Toast.makeText(getApplicationContext(), "refreshing",
                    Toast.LENGTH_LONG).show();
            refresh();
            return true;
        case upload:
            intent.setClass(Image_List.this, Custom_CameraActivity.class);
            intent.putExtra("username", username);
            startActivity(intent);
            return true;
        case search:
            intent.setClass(Image_List.this, SelectSpecies.class);
            startActivity(intent);
            return true;
        case map:
            intent.setClass(Image_List.this, Map.class);
            intent.putExtra("username", username);
            startActivity(intent);
            return true;
        case setting:
            intent.setClass(Image_List.this, Setting.class);
            intent.putExtra("username", username);
            startActivity(intent);
            return true;
        default:
            return super.onOptionsItemSelected(item);
        }
    }

    private void refresh() {

    }

    public void setRefreshActionButtonState(final boolean refreshing) {
        if (optionsMenu != null) {
            final MenuItem refreshItem = optionsMenu
                    .findItem(R.id.airport_menuRefresh);
            if (refreshItem != null) {
                if (refreshing) {
                    Toast.makeText(getApplicationContext(), "refreshing",
                            Toast.LENGTH_LONG).show();
                    startActivity(new Intent(Image_List.this, Image_List.class));
                    // refreshItem
                    // .setActionView(R.layout.actionbar_indeterminate_progress);
                } else {
                    refreshItem.setActionView(null);
                }
            }
        }
    }

    void go() {
        lv = (ListView) findViewById(R.id.imageListVIEW);
        lv.setAdapter(new CustomAdapter(this, image_name, image_id,
                image_sender_username, username, image_total_like, image_title,
                image_species));
    }

    class AmbilData extends AsyncTask<String, String, String> {
        ProgressDialog pDialog;

        @Override
        protected void onPreExecute() {
            // TODO Auto-generated method stub
            super.onPreExecute();
            pDialog = new ProgressDialog(Image_List.this);
            pDialog.setMessage("Loading Data");
            pDialog.setCancelable(true);
            pDialog.show();
        }

        @Override
        protected String doInBackground(String... args) {
            // TODO Auto-generated method stub
            List<NameValuePair> params = new ArrayList<NameValuePair>();
            String ip = new ip().call_IP();
            String link = ip + "/image/select_image_data.php";
            JSONObject json = jParser.makeHttpRequest(link, "GET", params);
            Log.d("image list", json.toString());
            try {
                int sukses = json.getInt(TAG_SUKSES);
                if (sukses == 1) {
                    member = json.getJSONArray(TAG_MEMBER);
                    new_String(member.length());

                    for (int i = 0; i < member.length(); i++) {
                        json_data = member.getJSONObject(i);

                        image_name[i] = json_data.getString(TAG_IMAGE_NAME);
                        image_total_like[i] = json_data
                                .getString(TAG_IMAGE_TOTAL_LIKE);
                        image_sender_username[i] = json_data
                                .getString(TAG_IMAGE_SENDER_USERNAME);

                        image_id[i] = json_data.getString(TAG_IMAGE_ID);
                        image_title[i] = json_data.getString(TAG_IMAGE_TITLE);
                        image_species[i] = json_data
                                .getString(TAG_IMAGE_SPECIES);

                    }
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
            return null;
        }

        private void new_String(int mLength) {
            image_id = new String[mLength];
            image_name = new String[mLength];
            image_total_like = new String[mLength];
            image_sender_username = new String[mLength];
            image_title = new String[mLength];
            image_species = new String[mLength];
        }

        @Override
        protected void onPostExecute(String result) {
            // TODO Auto-generated method stub
            super.onPostExecute(result);
            pDialog.dismiss();
            go();
        }

    }

}

所以我想记录所有操作菜单项。 并想知道如何使用res.drawable

中的drawable设置操作菜单项图标

我不知道该尝试什么,谢谢

所以我想记录所有操作菜单项。 并想知道如何使用res.drawable

中的drawable设置操作菜单项图标

我不知道该尝试什么,谢谢

这是我的布局代码

1 个答案:

答案 0 :(得分:0)

@Override
    public void onCreateOptionsMenu(Menu menu,MenuInflater inflater) {
        pmenu=menu;
        inflater = getActivity().getMenuInflater();
        inflater.inflate(R.menu.search_menu, menu);
        super.onCreateOptionsMenu(menu, inflater);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

         if(item.getItemId() == R.id.search){
                item.setChecked(!item.isChecked());
                item.setIcon(item.isChecked() ? R.drawable.ic_launcher : R.drawable.search_icon);
                return true;
              }
              return false;
    }