0

我已经在 android 中创建了一个应用程序,现在我已经创建了活动 notes.xml、contactinfo.xml 和一个名为 listplaceholder5.xml 的 android xml 文件,我需要在“listplaceholder5”中将 textview 的 android:text 更改为“notes” .xml”文件,它在note.java中使用,但它不显示“notes”,它显示“contact”。我试过sode a sbelow:请帮助我更改代码以便我可以解决它,

注意.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"

     >

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >


          <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Name: " 
            android:textColor="#000000"
            android:textStyle="bold"
            android:textSize="16sp"
            android:paddingLeft="5dp"



            />


           <TextView
            android:id="@+id/item_title"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="item_title"
            android:textColor="#000000"
            android:textStyle="bold"
            android:textSize="16sp"
            android:paddingLeft="5dp" 
            android:ellipsize="end" 
            android:lines="1"
            android:scrollHorizontally="true"

        />
    </LinearLayout>

   <LinearLayout
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

            <!--
            <TextView  
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content"
            android:layout_gravity="left"
            android:text="@string/hello"
            android:visibility="gone"



         />-->

            <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Phone  :  " 
            android:textColor="#000000"

            android:textSize="14sp"
            android:paddingLeft="5dp"

            />


             <TextView
             android:id="@+id/item_subtitle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"

            android:text="item_subtitle"

            android:textColor="#000000"
            android:textSize="14sp"

               />


          <TextView
            android:id="@+id/item_subtitle1"
            android:layout_height="wrap_content" 
            android:textColor="#000000"
            android:textSize="14sp" 
            android:layout_width="wrap_content"
             android:ellipsize="end" 
              android:lines="1"
              android:scrollHorizontally="true"


           />

            <!-- New Layout -->
            <LinearLayout
                android:orientation="horizontal"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:gravity="right" 
                android:paddingRight="10dp"
                >
                <ImageView
                    android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/forward" />
                </LinearLayout>
            </LinearLayout>

</LinearLayout>

listplaceholder5.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"

     android:background="@drawable/detailpage">
    <LinearLayout android:layout_width="fill_parent" 
        android:weightSum="1" 
        android:background="@drawable/bottombackground" 
        android:id="@+id/linearLayout1" 

        android:layout_height="wrap_content">
        <TextView 
            android:layout_width="wrap_content" 
            android:textColor="#FFFFFF" 
            android:layout_marginLeft="18dp" 
            android:layout_weight="0.88" 
            android:textSize="18sp" 
            android:textStyle="bold" 
            android:id="@+id/textView1" 
            android:text="Notes" 
            android:gravity="center"
            android:layout_gravity="center"
            android:layout_height="wrap_content">

        </TextView>
    </LinearLayout>


    <ListView
        android:id="@id/android:list"
        android:layout_height="wrap_content"

        android:drawSelectorOnTop="false"  
        android:layout_width="fill_parent"
        android:cacheColorHint="#00000000"
        android:dividerHeight="2dp"
        android:listSelector="@drawable/list_selector"
        />

    <TextView
        android:id="@id/android:empty"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="No data"/>

</LinearLayout>

注意活动.java

 package com.hussain.realtylog;

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

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.hussain.realtylog.Contact.DownloadWebPageTask;

import android.net.ConnectivityManager;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ListActivity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.GradientDrawable.Orientation;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.TextView;

public class NoteActivity extends ListActivity {
       JSONArray jArray = null;
       JSONObject json_data = null;
       String getMLSID =null;

       TextView titl;
      // Button btnBuyer;
     //  Button btnRental;
       String getJson =null;
       public String user=null;
       public static String urlContact=null;

       public static String jsonContact=null;
       ArrayList<HashMap<String, String>> mylist;

      private class DownloadWebPageTask extends AsyncTask<String, Void, String> {
        private ProgressDialog dialog;
        @Override
        protected String doInBackground(String... urls) {
            user= TabBarExample.getJsonUser;
            urlContact = StoreSession.strBaseURL+"&username="+user+"&act=ContactList";
             if( StoreSession.FlagContact == 0){
              boolean isNet = checkInternetConnection();
              if(isNet==true){
                jsonContact =  JSONfunctions.getJSONfromURL(urlContact);
              }else{
                alertbox("Contact", "Please check your mobile network setting and try again.");
              }
             }
             mylist = new ArrayList<HashMap<String, String>>();
             try{
               jArray = new JSONArray(jsonContact);
               for(int i=0;i<jArray.length();i++){                      
                HashMap<String, String> map = new HashMap<String, String>();    
                JSONObject e = jArray.getJSONObject(i);
                map.put("id",  String.valueOf(i));
                map.put("ID", e.getString("ID"));
                map.put("username", e.getString("username"));
                map.put("email",  e.getString("email"));
                map.put("phone", e.getString("phone"));
                map.put("phone2",  e.getString("phone2"));
                map.put("fullname",  e.getString("fullname"));
                map.put("address",  e.getString("address"));
                map.put("notes",  e.getString("info"));
                map.put("active",  e.getString("active"));
                map.put("created",  e.getString("created"));
                map.put("lastUpdate",  e.getString("lastUpdate"));
                map.put("guest",  e.getString("guest"));
                map.put("category",  "Category:  "+e.getString("category"));
                mylist.add(map);            
             }      
             }catch(JSONException e){
             //  Log.e("log_tag", "Error parsing data "+e.toString());
             }
             return null;
            }

        @Override
        protected void onPostExecute(String result) {

            ListAdapter adapter = new SimpleAdapter(NoteActivity.this, mylist , R.layout.activity_note, 
                        new String[] { "fullname", "phone" }, 
                        new int[] { R.id.item_title, R.id.item_subtitle });


            setListAdapter(adapter);

            final ListView lv = getListView();
            lv.setTextFilterEnabled(true);  
            int[] colors = {0, 0xFFFF0000, 0}; // red for the example
            lv.setDivider(new GradientDrawable(Orientation.RIGHT_LEFT, colors));
            lv.setDividerHeight(1);
            lv.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {                
                final ProgressDialog dialog = ProgressDialog.show(NoteActivity.this, "Loading", 
                        "Please wait...", true);
                    final Handler handler = new Handler() {
                        public void handleMessage(Message msg) {
                          dialog.dismiss();
                         }
                        };
                        Thread checkUpdate = new Thread() {  
                            @SuppressWarnings("unchecked")
                            public void run() {
                                HashMap<String, String> o = (HashMap<String, String>) lv.getItemAtPosition(position);                   
                                final String strName= o.get("fullname").toString();
                                final String strEmail= o.get("email").toString();
                                final String Phone= o.get("phone").toString();
                                final String Phone2= o.get("phone2").toString();
                                getMLSID = o.get("notes").toString();
                                Intent newActivityFirst = new Intent(NoteActivity.this, ContactInfo.class);
                                newActivityFirst.putExtra("name", strName);
                                newActivityFirst.putExtra("strEmail", strEmail);
                                newActivityFirst.putExtra("phone", Phone);
                                newActivityFirst.putExtra("phone2", Phone2);
                                newActivityFirst.putExtra("notes", getMLSID);
                                NoteActivity.this.startActivity(newActivityFirst);

                                handler.sendEmptyMessage(0);
                                }
                                };
                                checkUpdate.start();

                }
            });
            StoreSession.FlagContact=1;
            //dialog.hide();
            dialog.dismiss();
        }
        private ListView getListView() {
            // TODO Auto-generated method stub
            return null;
        }

        private void setListAdapter(ListAdapter adapter) {
            // TODO Auto-generated method stub

        }

        protected void onPreExecute() {
            dialog = new ProgressDialog(NoteActivity.this);
            dialog.setCancelable(true);
            dialog.setMessage("Please wait...");
            dialog.show();
        }
      }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_note);
         DownloadWebPageTask task = new DownloadWebPageTask();
            task.execute();

            setContentView(R.layout.listplaceholder5);

             TextView title=(TextView)findViewById(R.id.textView1); 
            title.setText("Notes");

    }

     @Override
        public boolean onKeyDown(int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK) {
                  StoreSession.FlagListing  =0;
                  StoreSession.FlagBuyer    =0;
                  StoreSession.FlagRental   =0;
                  StoreSession.FlagDocument =0;
                  StoreSession.FlagContact  =0;
                  ActiveShowingInfo.flagActiveClickCheck =0;
                  Main.username.setText("");
                  Main.pwd.setText("");

                return false;
            }
            return super.onKeyDown(keyCode, event);
        }

     protected void alertbox(String title, String mymessage)
        {
        new AlertDialog.Builder(this)
           .setMessage(mymessage)
           .setTitle(title)
           .setCancelable(true)
           .setNeutralButton(android.R.string.ok,
              new DialogInterface.OnClickListener() {
              public void onClick(DialogInterface dialog, int whichButton){}
              })
           .show();
        }
     private boolean checkInternetConnection() {
            ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
            // test for connection
            if (cm.getActiveNetworkInfo() != null
                    && cm.getActiveNetworkInfo().isAvailable()
                    && cm.getActiveNetworkInfo().isConnected()) {
                return true;
            } else {
                //Log.v("tag", "Internet Connection Not Present");
                return false;
            }
        }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_note, menu);
        return true;
    }

}

请帮我解决这个问题。提前谢谢你。

4

1 回答 1

1

得到标题后如下:

title= (TextView) findViewById(R.id.item_title);

使用setText方法根据需要设置标题。我认为它会解决你的问题。

于 2013-02-23T04:42:06.757 回答