0

これは私のソース コードです。リストビューに「ステータス」が表示されていません。残りのデータは表示されています」どこに問題があるのか​​ わかりません。この問題を解決しようとしている間、親切に助けてください。メールの送受信も行うアプリケーションで、メールボックスのソースコードです。メールボックスには、Status、From、Expert、Subject、Price が表示されます。

public class MailBox extends ListActivity {
    String userName;
    ListView MailList;
    //////contact JSonArray
    JSONArray contacts = null;
    String x;
    private static final String Status="a";
    String StatusVal="";
    private static final String From="b";
    String FromVal;
    private static final String Expert="c";
    String ExpertVal;
    private static final String Subject="d";
    private static final String Price="e";
    String SubjectVal;
     // JSON Node names
    private static final String TAG_CONTACTS = "list";
    private static final String TAG_ID = "mail_ID";
    private static final String TAG_STATUS = "mail_status";
    private static final String TAG_FROM_ID= "fromID";
    private static final String TAG_TO_ID= "toID";
    private static final String TAG_QUESTION= "questionid";
    private static final String TAG_PRICE= "mail_price";
     String xVal="";
     String arr[];
     Handler handler;
      // Hashmap for ListView
     ArrayList<HashMap<String, String>> contactList = new ArrayList<HashMap<String, String>>(); 
     ProgressDialog progressDialog;
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mail_box);
        MailList=(ListView) findViewById(R.id.list);
        final Bundle b=getIntent().getExtras();
        if(b!=null)
        {
        userName=b.getString("userName");
        }


        handler = new Handler();
        starttask();
    }
    public void starttask()
    {

        progressDialog = ProgressDialog.show(this,"" , "Logging In");
         Thread thread = new Thread() {
             public void run () {
             String url = "http://onlinesolutionproviders.com/apiosp.php?student_inbox=1&client_login_id="+userName;
                // Creating JSON Parser object   
        JSONParser jParser = new JSONParser();
        JSONObject json = jParser.getJSONFromUrl(url);
        HttpClient httpClient = new DefaultHttpClient();

         HttpContext httpContext= new BasicHttpContext();
        try {
            contacts = json.getJSONArray(TAG_CONTACTS);
            for(int i = 0; i < contacts.length(); i++){
              JSONObject c = contacts.getJSONObject(i);
              String id = c.getString(TAG_ID);
              String name = c.getString(TAG_STATUS);
              String fromid = c.getString(TAG_FROM_ID); 
              String toid = c.getString(TAG_TO_ID);
              String subject = c.getString(TAG_QUESTION); 
              String price = c.getString(TAG_PRICE); 
                HashMap<String, String> map = new HashMap<String, String>();
                map.put(TAG_ID, id);
                map.put(TAG_STATUS, name);//status
                map.put(TAG_FROM_ID, fromid);//from id
                map.put(TAG_TO_ID, toid);//expert name
                map.put(TAG_QUESTION, subject);//subject
                map.put(TAG_PRICE, price);//price
                String URL="http://onlinesolutionproviders.com/apiosp.php?client_email_subject=1&client_login_id="+userName+"&to_id="
                        +toid+"&from_id="+fromid+"&questionid="+id+"&status="+name;
                // Check your log cat for JSON reponse    
                Log.d("url mail box",URL);


                 HttpGet httpGet = new HttpGet(URL);

             try
             {
                HttpResponse response = httpClient.execute(httpGet, httpContext);
                HttpEntity hte=response.getEntity();
                InputStream is= hte.getContent();
                BufferedReader br=new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
                StringBuilder sb= new StringBuilder();
                String line=null;
                while ((line=br.readLine()) != null)
                {
                    sb.append(line + "");
                }
                is.close();
                 x= String.valueOf(Html.fromHtml(sb.toString()));

                Scanner scan= new Scanner(x);

                arr= new String[5];
                int j=0;
                while(scan.hasNextLine())
                {
                    arr[j]=scan.nextLine();
                    j++;
                }
                 map.put(Status, arr[0]);
                 map.put(From, arr[1]);
                 map.put(Expert, arr[2]);
                 map.put(Subject, arr[3]);       
                map.put(Price, arr[4]);   
             }
             catch (ClientProtocolException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                    Toast.makeText(getApplicationContext(), "OOps! Something went wrong. Restart the Application" , Toast.LENGTH_LONG).show();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                    Toast.makeText(getApplicationContext(), "OOps! Something went wrong. Restart the Application" , Toast.LENGTH_LONG).show();
                }

                contactList.add(map);

            }
        } catch (JSONException e) {
            e.printStackTrace();
        } 
            handler.post(new Runnable() {
             public void run() {
                 updateUI();
                 progressDialog.dismiss();



                                }
                            });

                        }

                    };

                    thread.start();


       }
     private void updateUI () {
         SpecialAdapter adapter = new SpecialAdapter(MailBox.this, contactList,
                    R.layout.list_item_mailbox,
                    new String[] { TAG_ID, Status, From, Expert, Subject, Price, TAG_FROM_ID,TAG_TO_ID,TAG_QUESTION, TAG_STATUS }, new int[] {
                           R.id.eID ,R.id.status_heading,  R.id.expert_heading,R.id.eexpert_heading, R.id.subject_heading, R.id.price_heading,
                           R.id.fromid, R.id.toid,R.id.question,R.id.statusid}); 
          setListAdapter(adapter);
          ListView lv = getListView();
            lv.setOnItemClickListener(new OnItemClickListener() {
                public void onItemClick(AdapterView<?> parent, View view,
                        int position, long id) {

                    /* for(int a = 0; a < parent.getChildCount(); a++)
                     {
                         parent.getChildAt(a).setBackgroundColor(Color.BLACK);
                     }

                     view.setBackgroundColor(Color.RED);*/
                    String mailid = ((TextView) view.findViewById(R.id.eID)).getText().toString();
                    String fromid = ((TextView) view.findViewById(R.id.fromid)).getText().toString();
                    String toid = ((TextView) view.findViewById(R.id.toid)).getText().toString();
                    String question = ((TextView) view.findViewById(R.id.question)).getText().toString();
                    String status = ((TextView) view.findViewById(R.id.status_heading)).getText().toString();
                    String pricetosend = ((TextView) view.findViewById(R.id.price_heading)).getText().toString();
                    Intent in = new Intent(getApplicationContext(), MailBoxDetail.class);
                    in.putExtra("mailid", mailid);
                    in.putExtra("fromid", fromid);
                    in.putExtra("toid", toid);
                    in.putExtra("question", question);
                    in.putExtra("userName", userName);
                    in.putExtra("status", status);
                    in.putExtra("pricetosend", pricetosend);
                    startActivity(in);
                }
            });
    }

これはspecialAdapterのコードです

package com.OSP.client;

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

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.SimpleAdapter;

public class SpecialAdapter extends SimpleAdapter {
    private int[] colors = new int[] { Color.parseColor("#FFFFFF"), Color.parseColor("#D8D8D8") };

        public SpecialAdapter(Context context, List<HashMap<String, String>> items, int resource, String[] from, int[] to) {
            super(context, items, resource, from, to);
        }

    @Override
        public View getView(int position, View convertView, ViewGroup parent) {
          View view = super.getView(position, convertView, parent);
          int colorPos = position % colors.length;
          view.setBackgroundColor(colors[colorPos]);
          return view;
        }
    }
4

1 に答える 1

0

Android 開発は初めてだと思います。ようこそ。

のメソッドで、これらのrow.xml行レイアウトのカスタム実装を自分で記述する必要があります。以下のコードを参照して、独自のものを作成できます:(非常に簡単)getViewSpecialAdapter

@Override
    public View getView ( int position, View convertView, ViewGroup parent ) {

        /* create a new view of my layout and inflate it in the row */
        convertView = ( RelativeLayout ) inflater.inflate( resource, null );

        /* Extract the city's object to show */
        City city = getItem( position );

        /* Take the TextView from layout and set the city's name */
        TextView txtName = (TextView) convertView.findViewById(R.id.cityName);
        txtName.setText(city.getName());

        /* Take the TextView from layout and set the city's wiki link */
        TextView txtWiki = (TextView) convertView.findViewById(R.id.cityLinkWiki);
        txtWiki.setText(city.getUrlWiki());

        /* Take the ImageView from layout and set the city's image */
        ImageView imageCity = (ImageView) convertView.findViewById(R.id.ImageCity);
        String uri = "drawable/" + city.getImage();
        int imageResource = context.getResources().getIdentifier(uri, null, context.getPackageName());
        Drawable image = context.getResources().getDrawable(imageResource);
        imageCity.setImageDrawable(image);
        return convertView;
    }

Getting Startedの部分を実行する必要がありますが、developer.android.comこれにより、tutorialより迅速に開始できます。

これが何らかの形で役に立った場合は、これを回答としてマークしてください。

于 2013-06-12T11:54:02.797 に答える