文本视图冲突的机器人

文本视图冲突的机器人

本文介绍了文本视图冲突的机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的布局XML

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="3"
 >
<ImageView
    android:id="@+id/photo_user"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/user_pic"
    android:layout_gravity="top"
    android:contentDescription="@string/image_descrip"
    />
<TextView
    android:id="@+id/text_user"
    android:layout_alignRight="@+id/photo_user"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/user_info"
    android:textColor="#FFFFFF"
    android:background="#AA000000"/>
   </RelativeLayout>
  <RelativeLayout
  android:layout_width="match_parent"
  android:layout_height="0dip"
  android:layout_weight="7"
  android:background="#000000"
   >
<RelativeLayout
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:paddingTop="10dp"
  android:paddingBottom="10dp"
    >
   <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:paddingLeft="15dp"
        android:text="@string/plan_text0"
        />
    <TextView
        android:id="@+id/tv_viewplan"
        android:layout_width="wrap_content"
        android:paddingLeft="100dp"
        android:textSize="12sp"
        android:layout_height="wrap_content"
        android:text="@string/plan_text"
        />
    <TextView
        android:id="@+id/tv_plan1"
        android:paddingLeft="215dp"
        android:textSize="12sp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/plan_text1"
        />
  </RelativeLayout>
<View
    android:id="@+id/place_view1"
   android:layout_width="fill_parent"
   android:layout_height="2dp"
   android:layout_marginTop="40dp"
   android:background="#5C5C5C"
    />
 <RelativeLayout
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
   android:layout_below="@+id/place_view1"
   android:paddingTop="10dp"
   android:paddingBottom="10dp"
    >
   <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:paddingLeft="15dp"
        android:text="@string/services_text0"
        />
    <TextView
        android:id="@+id/tv_service"
        android:layout_width="wrap_content"
        android:paddingLeft="100dp"
        android:textSize="12sp"
        android:layout_height="wrap_content"
        android:text="@string/services_text"
        />
    <TextView
        android:id="@+id/tv_service1"
        android:layout_below="@+id/tv_plan1"
        android:textSize="12sp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingLeft="215dp"
        android:text="@string/services_text1"
        />
  </RelativeLayout>
   <View
   android:id="@+id/place_view2"
   android:layout_width="fill_parent"
   android:layout_height="2dp"
   android:layout_marginTop="80dp"
   android:background="#5C5C5C"
    />
   <RelativeLayout
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
   android:layout_below="@+id/place_view2"
   android:paddingTop="10dp"
   android:paddingBottom="10dp"
    >
   <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:paddingLeft="15dp"
        android:text="@string/bill_text0"
        />
    <TextView
        android:id="@+id/tv_bill"
        android:layout_width="wrap_content"
        android:paddingLeft="100dp"
        android:textSize="12sp"
        android:layout_height="wrap_content"
        android:text="@string/bill_text"
        />
    <TextView
        android:id="@+id/tv_bill1"
        android:layout_below="@+id/tv_service1"
        android:paddingLeft="215dp"
         android:textSize="12sp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/bill_text1"
        />
  </RelativeLayout>
 <View
   android:id="@+id/place_view3"
   android:layout_width="fill_parent"
   android:layout_height="2dp"
   android:layout_marginTop="120dp"
   android:background="#5C5C5C"
    />
   <RelativeLayout
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
   android:layout_below="@+id/place_view3"
   android:paddingTop="10dp"
   android:paddingBottom="10dp"
    >
   <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:paddingLeft="15dp"
        android:text="@string/request_text0"
        />
    <TextView
        android:id="@+id/tv_request"
        android:layout_width="wrap_content"
        android:paddingLeft="100dp"
        android:textSize="12sp"
        android:layout_height="wrap_content"
        android:text="@string/request_text"
        />
    <TextView
        android:id="@+id/tv_request1"
        android:paddingLeft="215dp"
         android:textSize="12sp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/request_text1"
        />
  </RelativeLayout>
  <View
   android:id="@+id/place_view4"
   android:layout_width="fill_parent"
   android:layout_height="2dp"
   android:layout_marginTop="160dp"
    />
  <RelativeLayout
      android:layout_height="wrap_content"
      android:layout_width="match_parent"
      android:layout_below="@+id/place_view4"
      >
      <ExpandableListView
          android:id="@+id/ex_notifi"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          ></ExpandableListView>

  </RelativeLayout>



   </RelativeLayout>
</LinearLayout>

在我的福尔摩斯片段类我对所有文本的意见相同的听众

and in my sherlock fragment class i have same listener for all text views

      getView().findViewById(R.id.tv_viewplan).setOnClickListener(this);
  getView().findViewById(R.id.tv_plan1).setOnClickListener(this);
  getView().findViewById(R.id.tv_service).setOnClickListener(this);
  getView().findViewById(R.id.tv_service1).setOnClickListener(this);
  getView().findViewById(R.id.tv_bill).setOnClickListener(this);
  getView().findViewById(R.id.tv_bill1).setOnClickListener(this);
  getView().findViewById(R.id.tv_request).setOnClickListener(this);
  getView().findViewById(R.id.tv_request1).setOnClickListener(this);

在我的onclick听众

in my onclick listener

   switch(v.getId())
  {
    case R.id.tv_viewplan:
        System.out.println("Plan ids"  +v.getId());
        title= "My Plan"; tag = "viewplan_dialog";
        Utilsdialog dialog_vwplan = new Utilsdialog(context, R.layout.child, title, tag);
        dialog_vwplan.show(fm, tag);
         break;
    case R.id.tv_plan1:
     System.out.println("Plan ids"  +v.getId());
        title= "Change plan"; tag = "changeplan_dialog";
        Utilsdialog dialog_chgplan = new Utilsdialog(context, R.layout.child,title, tag);
        dialog_chgplan.show(fm, tag);
         break;
    case R.id.tv_service:
        Toast.makeText(getActivity(), "SELECTED VIEW SERVICE", Toast.LENGTH_LONG).show();
         break;

    case R.id.tv_service1:
        Toast.makeText(getActivity(), "SELECTED ADD SERVICE", Toast.LENGTH_LONG).show();
         break;
    case R.id.tv_request:

        Toast.makeText(getActivity(), "SELECTED TRACK REQUEST", Toast.LENGTH_LONG).show();
         break;
    case R.id.tv_request1:

        Toast.makeText(getActivity(), "SELECTED ADD REQUEST", Toast.LENGTH_LONG).show();
         break;
    case R.id.tv_bill:

        Toast.makeText(getActivity(), "SELECTED VIEW BILL", Toast.LENGTH_LONG).show();
         break;
    case R.id.tv_bill1:

        Toast.makeText(getActivity(), "SELECTED PAY BILL", Toast.LENGTH_LONG).show();
         break;

     }

问题是tv_viewplan并产生tv_plan相同的id,也为tv_service和tv_servive1具有相同的ID。所以切换接听电话不正确的块。我唐诺这怎么可能....请帮助

The problem is for tv_viewplan and tv_plan same id is generated and also for tv_service and tv_servive1 has same ids. so switch calls incorrect block. I donno how is this possible....pls help

推荐答案

清理和重建项目,并确保每个TextView的不重复的ID

Clean and Rebuild your project and make sure no duplicate ids on each textview

如果没有工作,尽量做到这一点。

if didn't work, try to do this

为什么你不只是删除所有
      getView()findViewById(R.id.tv_viewplan).setOnClickListener(本);

why won't you just remove all getView().findViewById(R.id.tv_viewplan).setOnClickListener(this);

和添加
     安卓的onclick =clickText
在每一个TextView的可点击的

and add android:onclick="clickText"in every textView that are clickable

然后添加此功能

 public void clickText(View v){
 //put your switch case here...
 }

这篇关于文本视图冲突的机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 12:32