如何在列表上方显示文本,我使用ListActivity显示自定义列表

如何解决如何在列表上方显示文本,我使用ListActivity显示自定义列表

|| 亲 当我在类文件中扩展listactivity时,如何在自定义列表上方显示文本。代码如下。
public class ServerResponce extends ListActivity {
        private ArrayList<listobj> tobj = new ArrayList<listobj>();
         static String str1;
        PickUpLocation pickup=new PickUpLocation();
        String pickupLocid=  pickup.locationid;
        String des=planner.description;
         @Override
         public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
      **//here not work force close**
                  //     ****setContentView(R.layout.list_item);

**//                    TextView tv = (TextView)findViewById(R.id.text1);
//                       tv.setText(\"i want to book a  cab for 4 hr/40km from sushant lok to delhi air port at\" +
//                          \"4 pm today\"
//                           +\"the cab should be 4 seater compact cab with carriage\");
//                            tv.setBackgroundColor(R.color.black);**    
//        


         new MyTask().execute();
         }         

      private class MyTask extends AsyncTask<Void,Void,Void>
      {
              private ProgressDialog progressDialog;
              protected void onPreExecute() {
                      progressDialog = ProgressDialog.show(ServerResponce.this,\"\",\"Loading. Please wait...\",true);
              }

              protected void onProgressUpdate(Integer... integer){
                  TextView tv = null;
                tv.setText(\"gjh\");
              }
              @Override
              protected Void doInBackground(Void... arg0) {
                      try {



                          URL url = new URL(\"http://qrrency.com/mobile/j2me/cab/CabBookingStatus.PHP?requestid=666\");
                          BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
                          int l=0;
                          int k=0;
                          StringBuffer buffer=new StringBuffer();
                          String str=\" \";
                          while ((l=in.read())!=-1) 
                          {
                                buffer.append((char)l);
                                str=str+(char)l;

                          } 

                           in.close();
//                                  
                                try {
                            JSONObject json = new JSONObject(str);
                            JSONArray nameArray=json.getJSONArray(\"bookings\");
                            JSONObject[] cabListing=new JSONObject[nameArray.length()];
                            for (int i = 0; i < cabListing.length; i++) {

                                //JSONObject jSONObject = cabListing[i];
                                 JSONObject jSONObject = nameArray.getJSONObject(i);
                                 listobj tweet = new listobj();
                                 JSONObject temp=jSONObject.getJSONObject(\"booking\");
                                 tweet.cabid = temp.getString(\"cabbookingid\");
                                 tweet.author =temp.getString(\"CabDriverName\");
                                 tweet.content =temp.getString(\"price\");
                                 tweet.cabrat=temp.getString(\"cabrating\");
                                 tobj.add(tweet);
                            }
                            } catch (JSONException e) {
                                // Todo Auto-generated catch block
                                e.printstacktrace();
                            }

                        } catch (MalformedURLException e)
                        {
                        } catch (IOException e) 
                        {

                    }




                  return null;
              }

        @Override
        protected void onPostExecute(Void result) {
                progressDialog.dismiss();
                setlistadapter(new tListAdaptor(
                              ServerResponce.this,R.layout.list_item,tobj));
         }
    }
    private class tListAdaptor extends ArrayAdapter<listobj> {
            private ArrayList<listobj> tobj;
            public tListAdaptor(Context context,int textViewResourceId,ArrayList<listobj> items)
            {

                      super(context,textViewResourceId,items);
                      this.tobj = items;
            }
            @Override
            public View getView(int position,View convertView,ViewGroup parent) {
                    View v = convertView;
                    if (v == null) {
                            LayoutInflater vi = (LayoutInflater)
                                     getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                            v = vi.inflate(R.layout.list_item,null);

                    }
                    listobj o = tobj.get(position);


                    TextView tt = (TextView) v.findViewById(R.id.toptext);
                    TextView bt = (TextView) v.findViewById(R.id.bottomtext);
                    TextView bt1 = (TextView) v.findViewById(R.id.bottomtext1);
                    TextView bt2 = (TextView) v.findViewById(R.id.bottomtext2);
                    bt.setText(\"CAB NAME: \" +o.author);
                    bt1.setText(\"CAB ID:  \" +o.cabid);
                    tt.setText(\"PRICE:  \" +o.content); 
                    bt2.setText(\"CAB rating:  \" +o.cabrat);
                    return v;
            }
       }
    public String getItem(int position) {
        // Todo Auto-generated method stub
        return null;
    }
}
xml文件是...
<?xml version=\"1.0\" encoding=\"utf-8\"?>
<LinearLayout xmlns:android= \"http://schemas.android.com/apk/res/android\"
  android:orientation=\"vertical\"
  android:layout_width=\"fill_parent\"
  android:layout_height=\"fill_parent\"
    >

    <RelativeLayout xmlns:android= \"http://schemas.android.com/apk/res/android\"
  android:orientation=\"vertical\"
  android:layout_width=\"fill_parent\"
  android:layout_height=\"wrap_content\"
  android:paddingTop=\"6dip\">

   <TextView android:id=\"@+id/text\" android:layout_width=\"fill_parent\"
      android:layout_height=\"wrap_content\"
       android:singleLine=\"false\" 
       android:text=\" \"
       android:textStyle=\"italic\"
       />
       <Button 
         android:text=\"auto book\" 
         android:id=\"@+id/autobook\"
         android:layout_width=\"wrap_content\"
         android:layout_height=\"wrap_content\" 
         android:layout_below=\"@id/text\"/>
          <Button 
         android:text=\"cancel\" 
         android:id=\"@+id/cancel\"
         android:layout_width=\"wrap_content\"
         android:layout_height=\"wrap_content\" 
         android:layout_below=\"@id/text\"
         android:layout_toRightOf=\"@id/autobook\"/>

  </RelativeLayout>
           <LinearLayout
       android:orientation=\"vertical\"
       android:layout_width=\"fill_parent\"
       android:layout_height=\"fill_parent\"
       android:layout_weight=\"1\">

  <TextView android:id=\"@+id/toptext\" android:layout_width=\"fill_parent\"
      android:layout_height=\"wrap_content\"
       android:singleLine=\"true\"
       android:text=\" \" />
  <TextView android:id=\"@+id/bottomtext\" android:layout_width=\"fill_parent\"
      android:layout_height=\"wrap_content\"
       android:singleLine=\"true\" />
      <TextView android:id=\"@+id/bottomtext1\" android:layout_width=\"fill_parent\"
      android:layout_height=\"wrap_content\"
       android:singleLine=\"true\"
       android:text=\" \" />
      <TextView android:id=\"@+id/bottomtext2\" android:layout_width=\"fill_parent\"
      android:layout_height=\"wrap_content\"
       android:singleLine=\"true\" />
       </LinearLayout>
</LinearLayout>
    

解决方法

您可以通过textview设置标题。它仍将具有与列表视图相同的格式,但是列表视图中的第一项将是您的文本视图     ,您的代码正在寻找R.id.text1
TextView tv = (TextView)findViewById(R.id.text1);
但是您的xml没有任何此类ID。 因此,您将获得电视空值。     

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?
Java在半透明框架/面板/组件上重新绘画。
Java“ Class.forName()”和“ Class.forName()。newInstance()”之间有什么区别?
在此环境中不提供编译器。也许是在JRE而不是JDK上运行?
Java用相同的方法在一个类中实现两个接口。哪种接口方法被覆盖?
Java 什么是Runtime.getRuntime()。totalMemory()和freeMemory()?
java.library.path中的java.lang.UnsatisfiedLinkError否*****。dll
JavaFX“位置是必需的。” 即使在同一包装中
Java 导入两个具有相同名称的类。怎么处理?
Java 是否应该在HttpServletResponse.getOutputStream()/。getWriter()上调用.close()?
Java RegEx元字符(。)和普通点?