漆黑天使复活 2016-05-14 04:01 采纳率: 44.4%
浏览 3604
已采纳

android textview内容消失问题

我做了一个简单的fragment界面,主要是输入ID,然后向服务器查询内容后赋值回原来的界面上的textview,但是在运行的时候发生了一个奇怪的问题,一部分的textview消失了,具体很难描述,以下是整个过程的描述
图片说明
这是个原始界面,在最上方输入编号,然后查询。
图片说明
点击查询后,可以看见,背景内容已经加载,textview的内容已经进去了,但是加载完成后,textview
图片说明
如上图,加载完成后,下面的Textview不见了,而且,连那些实现写好的静态的textview也不见了
然后,我通过弹出输入法,用输入法覆盖部分内容
图片说明
像上图这样,在搜索框中点击之后,输入法会自动弹出,覆盖掉下面的内容,然后再取消
图片说明
然后内容就出来了。。。

每次都是这个样子。。我觉得很奇怪,不知道什么原因导致的,谁能帮忙看看吗?谢谢

整个框架大框架是fragment+viewpage,查询用的AsyncTask查询后赋值。

上代码了,布局文件,是一个fragment_content,xml

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

<LinearLayout
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">
    <EditText
        android:layout_width="270dip"
        android:layout_height="52dip"
        android:id="@+id/searchText"
        android:hint="请输入客户编号ID或扫二维码"
        android:background="@android:drawable/editbox_background_normal"/>
    <ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@android:drawable/ic_menu_search"
        android:id="@+id/search_button"/>
    <ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@android:drawable/ic_menu_camera"
        android:id="@+id/search_QRcode"/>
</LinearLayout>
<LinearLayout
    android:layout_marginTop="5dip"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:background="#F2F3EB">
    <TextView
        android:layout_width="360dip"
        android:layout_height="35dip"
        android:text="业主信息"
        android:gravity="center"
        android:layout_gravity="center"
        android:layout_marginTop="8dip"
        android:background="@android:drawable/btn_default"
        />
    <LinearLayout
        android:layout_marginTop="8dip"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <TextView
            android:layout_width="100dip"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="业主名称"/>
        <TextView
            android:id="@+id/CustomerNAME"
            android:layout_width="300dip"
            android:layout_height="wrap_content"
            android:text="请输入客户ID"
            android:gravity="center"/>
    </LinearLayout>
    <LinearLayout
        android:layout_marginTop="8dip"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <TextView
            android:layout_width="100dip"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="行业性质"/>
        <TextView
            android:layout_width="300dip"
            android:layout_height="wrap_content"

            android:gravity="center"
            android:id="@+id/CustomerSegment"/>
    </LinearLayout>
    <LinearLayout
        android:layout_marginTop="8dip"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <TextView
            android:layout_width="100dip"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="联系地址"/>
        <TextView
            android:layout_width="300dip"
            android:layout_height="wrap_content"
            android:id="@+id/CustomerAddress"
            android:gravity="center"/>
    </LinearLayout>
    <LinearLayout
        android:layout_marginTop="8dip"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <TextView
            android:layout_width="100dip"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="联系人"/>
        <TextView
            android:layout_width="300dip"
            android:layout_height="wrap_content"
            android:id="@+id/CustomerContactor"
            android:gravity="center"/>
    </LinearLayout>
    <LinearLayout
        android:layout_marginTop="8dip"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        >
        <TextView
            android:layout_width="100dip"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="联系电话"/>
        <TextView
            android:layout_width="300dip"
            android:layout_height="wrap_content"
            android:id="@+id/CustomerPhone"
            android:gravity="center"/>
    </LinearLayout>
    <LinearLayout
        android:layout_marginLeft="4dip"
        android:layout_marginTop="8dip"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginBottom="5dip">
        <TextView
            android:layout_width="100dip"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="保养合约到期时间"/>
        <TextView
            android:layout_width="300dip"
            android:layout_height="wrap_content"
            android:id="@+id/Customercontactdate"
            android:gravity="center"/>
    </LinearLayout>
//下面开始就是出问题的部分布局
</LinearLayout>
    <LinearLayout
        android:layout_marginTop="10dip"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:background="#F2F3EB">
        <TextView
            android:layout_width="360dip"
            android:layout_height="35dip"
            android:text="维护人员信息"
            android:gravity="center"
            android:layout_gravity="center"
            android:layout_marginTop="8dip"
            android:background="@android:drawable/btn_default"
            />
        <TextView
            android:layout_width="400dip"
            android:layout_height="30dip"
            android:text="专属客户代表"
            android:gravity="center" />
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:layout_marginBottom="10dip">

                <ImageView
                    android:layout_width="120dip"
                    android:layout_height="100dip"
                    android:src="@drawable/unknownpic"
                    android:id="@+id/SRPIC"/>

            <TableLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                >

            <TableRow
                android:layout_marginTop="7dip">
                <TextView
                    android:layout_width="70dip"
                    android:layout_height="wrap_content"
                    android:text="姓名"
                    android:gravity="center"/>
                <TextView
                    android:layout_width="220dip"
                    android:layout_height="match_parent"
                    android:id="@+id/ServiceRepresentive"
                    android:gravity="center"/>
            </TableRow>
                <TableRow
                    android:layout_marginTop="7dip">
                    <TextView
                        android:layout_width="70dip"
                        android:layout_height="wrap_content"
                        android:text="职位"
                        android:gravity="center"/>
                    <TextView
                        android:layout_width="220dip"
                        android:layout_height="match_parent"
                        android:id="@+id/SRP"
                        android:gravity="center"/>
                </TableRow>
                <TableRow
                    android:layout_marginTop="7dip">
                    <TextView
                        android:layout_width="70dip"
                        android:layout_height="wrap_content"
                        android:text="联系方式"
                        android:gravity="center"/>
                    <TextView
                        android:layout_width="220dip"
                        android:layout_height="match_parent"
                        android:id="@+id/SRN"
                        android:gravity="center"/>
                </TableRow>
                <TableRow
                    android:layout_marginTop="7dip">
                    <TextView
                        android:layout_width="70dip"
                        android:layout_height="wrap_content"
                        android:text="工作年限"
                        android:gravity="center"/>
                    <TextView
                        android:layout_width="220dip"
                        android:layout_height="match_parent"
                        android:id="@+id/SRY"
                        android:gravity="center"/>
                </TableRow>
            </TableLayout>

        </LinearLayout>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">
            <TextView
                android:layout_width="400dip"
                android:layout_height="30dip"
                android:text="专属服务技师"
                android:gravity="center" />
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:layout_marginBottom="10dip">

                <ImageView
                    android:layout_width="120dip"
                    android:layout_height="100dip"
                    android:src="@drawable/unknownpic"
                    android:id="@+id/STPIC"/>

                <TableLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    >

                    <TableRow
                        android:layout_marginTop="7dip">
                        <TextView
                            android:layout_width="70dip"
                            android:layout_height="wrap_content"
                            android:text="姓名"
                            android:gravity="center"/>
                        <TextView
                            android:layout_width="220dip"
                            android:layout_height="match_parent"
                            android:id="@+id/ServiceTechnician"
                            android:gravity="center"/>
                    </TableRow>
                    <TableRow
                        android:layout_marginTop="7dip">
                        <TextView
                            android:layout_width="70dip"
                            android:layout_height="wrap_content"
                            android:text="职位"
                            android:gravity="center"/>
                        <TextView
                            android:layout_width="220dip"
                            android:layout_height="match_parent"
                            android:id="@+id/STN"
                            android:gravity="center"/>
                    </TableRow>

                    <TableRow
                        android:layout_marginTop="7dip">
                        <TextView
                            android:layout_width="70dip"
                            android:layout_height="wrap_content"
                            android:text="工作年限"
                            android:gravity="center"/>
                        <TextView
                            android:layout_width="220dip"
                            android:layout_height="match_parent"
                            android:id="@+id/STY"
                            android:gravity="center"/>
                    </TableRow>
                    <TableRow
                        android:layout_marginTop="7dip">
                        <TextView
                            android:layout_width="70dip"
                            android:layout_height="wrap_content"
                            android:text="专业技能"
                            android:gravity="center"/>
                        <TextView
                            android:layout_width="220dip"
                            android:layout_height="match_parent"
                            android:id="@+id/STS"
                            android:gravity="center"/>
                    </TableRow>
                </TableLayout>

            </LinearLayout>
        </LinearLayout>
    </LinearLayout>
</LinearLayout>
</ScrollView>

fragment的文件,里面除了查询,还有一个二维码扫描

 public class CustomerInf extends Fragment {
    ImageButton search,search_QRcode;
    EditText editText;
    String searchID;
    TextView CustomerName,CustomerSegment,CustomerAddress,CustomerContactor,CustomerPhone;
    TextView Customercontactdate,ServiceRepresentive,SRP,SRN,SRY,ServiceTechnician,STN,STY,STS;
    ImageView SRPIC,STPIC;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_content, container, false);
        bind(view);
        return view;

    }
//对各内容进行绑定
    public void bind(View view) {
        search = (ImageButton) view.findViewById(R.id.search_button);
        editText = (EditText) view.findViewById(R.id.searchText);
        CustomerName=(TextView)view.findViewById(R.id.CustomerNAME);
        CustomerSegment=(TextView)view.findViewById(R.id.CustomerSegment);
        CustomerAddress=(TextView)view.findViewById(R.id.CustomerAddress);
        CustomerContactor=(TextView)view.findViewById(R.id.CustomerContactor);
        CustomerPhone=(TextView)view.findViewById(R.id.CustomerPhone);
        Customercontactdate=(TextView)view.findViewById(R.id.Customercontactdate);
        ServiceRepresentive=(TextView)view.findViewById(R.id.ServiceRepresentive);
        SRP=(TextView)view.findViewById(R.id.SRP);
        SRN=(TextView)view.findViewById(R.id.SRN);
        SRY=(TextView)view.findViewById(R.id.SRY);
        ServiceTechnician=(TextView)view.findViewById(R.id.ServiceTechnician);
        STN=(TextView)view.findViewById(R.id.STN);
        STY=(TextView)view.findViewById(R.id.STY);
        STS=(TextView)view.findViewById(R.id.STS);
        SRPIC=(ImageView) view.findViewById(R.id.SRPIC);
        STPIC=(ImageView) view.findViewById(R.id.STPIC);
        search.setOnClickListener(new Click());
        search_QRcode=(ImageButton)view.findViewById(R.id.search_QRcode);
        search_QRcode.setOnClickListener(new QRsearch());
    }

        //此处是一个引用外部二维码扫描的程序
    public class QRsearch implements View.OnClickListener{
        @Override
        public void onClick(View v){
            if (ContextCompat.checkSelfPermission(getContext(),
                    Manifest.permission.CAMERA)
                    != PackageManager.PERMISSION_GRANTED) {

                if (ActivityCompat.shouldShowRequestPermissionRationale(getActivity(),
                        Manifest.permission.CAMERA)) {



                } else {



                    requestPermissions(
                            new String[]{Manifest.permission.CAMERA},
                            123);


                }
            } else {
                Toast.makeText(getContext(),"开始扫描",Toast.LENGTH_SHORT).show();
                Intent startScan=new Intent(getContext(), CaptureActivity.class);
                startActivityForResult(startScan, Activity.RESULT_FIRST_USER);
            }

        }

    }

        //二维码的返回
    @Override
    public void onActivityResult(int requestCode,int resultCode,Intent data){
        super.onActivityResult(requestCode,resultCode,data);
        if(resultCode==Activity.RESULT_OK){
            Bundle bundle = data.getExtras();
            String scanResult = bundle.getString("result");
            editText.setText(scanResult);
            searchID = editText.getText().toString().trim();
            if (TextUtils.isEmpty(searchID)) {
                Toast.makeText(getActivity(), "请输入客户ID"+searchID, Toast.LENGTH_LONG).show();
            } else {
                SearchTask searchTask = new SearchTask();
                String[] array=new String[]{"http://www.klmt001.com/CustomerINF.php",searchID};
                searchTask.execute(array);
            }
        }
    }
        //这里是查询按钮的监听器
    public class Click implements View.OnClickListener {
        @Override
        public void onClick(View v) {
            searchID = editText.getText().toString().trim();
            if (TextUtils.isEmpty(searchID)) {
                Toast.makeText(getActivity(), "请输入客户ID"+searchID, Toast.LENGTH_LONG).show();
            } else {
                SearchTask searchTask = new SearchTask();
                String[] array=new String[]{"http://www.klmt001.com/CustomerINF.php",searchID};
                searchTask.execute(array);
            }

        }
    }
//监听按钮的AsyncTask
    class SearchTask extends AsyncTask<String, Integer, JSONObject> {
ProgressDialog p1;

        @Override
        protected void onPreExecute() {
            p1=new ProgressDialog(getActivity());
            p1.setTitle("请等待");
            p1.setMessage("等待中........");
           p1.setCancelable(false);
            p1.show();
          new Handler().postDelayed(new Runnable(){

                public void run() {

                   p1.dismiss();

                }

            }, 1000);

        }

        protected JSONObject doInBackground(String... inf) {
            HttpClient httpclient = new DefaultHttpClient();
            HttpEntity entity = null;

            StringBuilder builder = new StringBuilder();

            JSONObject jsonObject=null;
            try {
                HttpPost httpPost = new HttpPost(inf[0]);
                List<NameValuePair> list = new ArrayList<>();
                list.add(new BasicNameValuePair("CustomerID", inf[1]));
                httpPost.setEntity(new UrlEncodedFormEntity(list, HTTP.UTF_8));
                HttpResponse response = httpclient.execute(httpPost);
                entity = response.getEntity();
                if (response.getEntity() != null) {
                    if (response.getEntity().toString().equals("0")) {
                        jsonObject=null;
                        Log.v("msg",""+"没有收到信息");
                    } else {
                        BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
                        String s = reader.readLine();
                        for (; s != null; s = reader.readLine()) {
                            builder.append(s);
                        }
                        Log.v("msg",""+"成功获取信息");
                        jsonObject = new JSONObject(builder.toString());
                    }
                }
            } catch (Exception E) {
                Log.e("msg", E.getMessage());
                Log.v("msg",
                        "没有成功 ");
            } finally {
                try {
                    if (entity != null) {
//                  entity.consumeContent();//强制释放资源
                        httpclient.getConnectionManager().shutdown();//关闭连接
                        //这两种释放连接的方法都可以
                    }
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

            }
            return jsonObject;
        }
//获取值之后开始对原来的textview进行赋值
        protected void onPostExecute(JSONObject webcontent){

            String cn,cs,ca,cc,cp,cd,sr,srd,srn,sry,st,stn,sty,sts,pic1,pic2;

            if(webcontent==null){
                Toast.makeText(getActivity(),"没有对应的客户信息",Toast.LENGTH_LONG).show();
            }else {
               try {
                   cn=webcontent.getString("CustomerName");
                   CustomerName.setText(cn);
                   cs=webcontent.getString("CustomerSegment");
                   CustomerSegment.setText(cs);
                   ca=webcontent.getString("CustomerAddress");
                   CustomerAddress.setText(ca);
                   cc=webcontent.getString("CustomerContactor");
                   CustomerContactor.setText(cc);
                   cp=webcontent.getString("CustomerPhone");
                   CustomerPhone.setText(cp);
                   cd=webcontent.getString("Customercontactdate");
                   Customercontactdate.setText(cd);
                   sr=webcontent.getString("ServiceRepresentive");
                   ServiceRepresentive.setText(sr);
                   srd=webcontent.getString("SRP");
                   SRP.setText(srd);
                   srn=webcontent.getString("SRN");
                   SRN.setText(srn);
                   sry=webcontent.getString("SRY");
                   SRY.setText(sry);
                   st=webcontent.getString("ServiceTechnician");
                   ServiceTechnician.setText(st);
                   stn=webcontent.getString("STN");
                   STN.setText(stn);
                   sty=webcontent.getString("STY");
                   STY.setText(sty);
                   sts=webcontent.getString("STS");
                   STS.setText(sts);
                   pic1=webcontent.getString("SRPIC");
                   pic2=webcontent.getString("STPIC");
                   String[] pics=new String[]{pic1,pic2};
                   Loadpics loadpics=new Loadpics();
                   loadpics.execute(pics);
               }catch (Exception E){
                   E.printStackTrace();
               }

            }

        }


    }
        //这里是用来获取图片的
    class Loadpics extends AsyncTask<String, Integer, Bitmap[]>{
        protected Bitmap[] doInBackground(String... inf) {
            Bitmap[] bitmaps=new Bitmap[2];
            Bitmap bitmap1,bitmap2;
            try{
                URL url1=new URL(inf[0]);
                URLConnection conn1=url1.openConnection();
                conn1.connect();
                InputStream inputStream = conn1.getInputStream();
                bitmap1 = BitmapFactory.decodeStream(inputStream);
                URL url2=new URL(inf[1]);
                URLConnection conn2=url2.openConnection();
                conn2.connect();
                InputStream inputStream2 = conn2.getInputStream();
                bitmap2 = BitmapFactory.decodeStream(inputStream2);
                bitmaps[0]=bitmap1;
                bitmaps[1]=bitmap2;
            }catch (Exception E){
                Log.e("msg", E.getMessage());
            }return bitmaps;

        }
        protected void onPostExecute(Bitmap[] bitmap){
            try{
                SRPIC.setImageBitmap(bitmap[0]);
                STPIC.setImageBitmap(bitmap[1]);
            }catch (Exception E){
                Log.e("msg", E.getMessage());
        }
    }

}}
  • 写回答

5条回答 默认 最新

  • glustful 2016-05-14 04:08
    关注

    应该是你代码有问题,没代码也看不出什么东西来,上代码吧

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

问题事件

  • 已采纳回答 8月23日

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化