为什么在我第一次启动应用程序时单行显示textview?

时间:2019-04-01 02:18:03

标签: android textview

我的应用程序中有一个非常奇妙的问题。我的活动中有一个文本视图,该文本视图是从sqlite获取的文本,如下所示:

Hello

World!

但是当我第一次启动我的应用程序时,我的文本视图会显示如下文本:

Hello word!

当我离开应用程序并清除我的应用程序RAM内存,然后返回到应用程序时,我的文本视图会像下面这样正确显示文本:

Hello

World!

实际上,当第一次运行onCreate方法时,我的文本视图文本以单行显示。我尝试了类似使用recreate方法的方法:

public void recreate() {
    this.recreate();
}

在onCreate方法中:

recreate();

但是我的应用程序崩溃了! 有办法解决这个问题吗?谢谢

我的魅力1:

   String pattern = "'%" + inputSearch.getText().toString() + "%'";

   final String sql = "SELECT * FROM " + TABLE + " WHERE " + MAANY + " LIKE " + pattern;        

   final SQLiteDatabase mydb = new MyDatabase2(EnglishActivity.this).getWritableDatabase();
   final Cursor c = mydb.rawQuery(sql, null);

   Cursor cT = mydb.rawQuery(" SELECT * FROM "+ TABLE + " WHERE " 
                    + TITLE + " LIKE ? " ,new String []{inputSearch.getText()+"%"});

   Cursor c2=mydb.rawQuery(" SELECT * FROM "+ TABLE + " WHERE " 
                                + MAANY + " LIKE ? " ,new String []{inputSearch.getText()+"%"});

   lv=(ListView)findViewById(R.id.enlist);
   listItems=new ArrayList<String>();
   lv2=(ListView)findViewById(R.id.enlist2);
   listItems2=new ArrayList<String>();

   array = new String[cT.getCount()];
   array2 = new String[cT.getCount()];
   array3 =new int[cT.getCount()];
   int i = 0;
   while(cT.moveToNext()){
       String uname = cT.getString(cT.getColumnIndex(TITLE));
       array[i] = uname;
       String maany = cT.getString(cT.getColumnIndex(MAANY));
       array2[i] = maany;
       array3[i]=cT.getInt(cT.getColumnIndex(ID));
       i++;
   }

   arrayMaany = new String[c.getCount()];
   arrayMaany2 = new String[c.getCount()];
   arrayMaany3 =new int[c.getCount()];
   int ii = 0;
   while(c.moveToNext()){
       String uname = c.getString(c.getColumnIndex(TITLE));
       arrayMaany[ii] = uname;
       String maany = c.getString(c.getColumnIndex(MAANY));
       arrayMaany2[ii] = maany;
       arrayMaany3[ii]=c.getInt(c.getColumnIndex(ID));
       ii++;
   }

   final ArrayList<String> forNum1 = new ArrayList<String>(Arrays.asList(array));

   if(forNum1.size()==0){
       lv2.setVisibility(View.VISIBLE);
   } else if(forNum1.size()>0) {
       lv2.setVisibility(View.GONE);
   }
   Typeface tf = Typeface.createFromAsset(getAssets(),"font/Harir Bold.otf");

   lv.setAdapter(new EnCustomAdapter(EnglishActivity.this,array,array2,tf));

   lv2.setAdapter(new 
   EnCustomAdapter(EnglishActivity.this,arrayMaany,arrayMaany2,tf));

   lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
       @Override
       public void onItemClick(AdapterView<?> parent, final View view, int position, long id) {
           String i=array[position];
           String ii=array2[position];
           int iii=array3[position];

           SharedPreferences en = getApplicationContext().getSharedPreferences("enn1",  1);
           final SharedPreferences.Editor editorEn = en.edit();
           String enn = en.getString("enn2" , i);
           enn=i;
           editorEn.putString("enn2", i);
           editorEn.commit();

           SharedPreferences fa = getApplicationContext().getSharedPreferences("faa1",  1);
           final SharedPreferences.Editor editorFa = fa.edit();
           String faa = fa.getString("faa2" , ii);
           faa=ii;
           editorFa.putString("faa2", ii);
           editorFa.commit();

           SharedPreferences idd = getApplicationContext().getSharedPreferences("id1",  1);
           final SharedPreferences.Editor editorId = idd.edit();
           int iddd = idd.getInt("id2" , iii);
           iddd=iii;
           editorId.putInt("id2", iii);
           editorId.commit();

           startActivity(new Intent(EnglishActivity.this,ArMaany.class));

           overridePendingTransition(R.anim.animation_zoom_in_speed, R.anim.animation_zoom_out_speed);              
        }
    });



    lv2.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, final View view, int position, long id) {
            String i=arrayMaany[position];
            String ii=arrayMaany2[position];
            int iii=arrayMaany3[position];

            SharedPreferences en = getApplicationContext().getSharedPreferences("enn1",  1);
            final SharedPreferences.Editor editorEn = en.edit();
            String enn = en.getString("enn2" , i);
            enn=i;
            editorEn.putString("enn2", i);
            editorEn.commit();

            SharedPreferences fa = getApplicationContext().getSharedPreferences("faa1",  1);
            final SharedPreferences.Editor editorFa = fa.edit();
            String faa = fa.getString("faa2" , ii);
            faa=ii;
            editorFa.putString("faa2", ii);
            editorFa.commit();

            SharedPreferences idd = getApplicationContext().getSharedPreferences("id1",  1);
            final SharedPreferences.Editor editorId = idd.edit();
            int iddd = idd.getInt("id2" , iii);
            iddd=iii;
            editorId.putInt("id2", iii);
            editorId.commit();

            startActivity(new Intent(EnglishActivity.this,ArMaany.class));

            overridePendingTransition(R.anim.animation_zoom_in_speed, R.anim.animation_zoom_out_speed);             

        }
    });

    c.close();
    c2.close();
    mydb.close();
}});

我的活动2:

final String enmaany = getSharedPreferences("enn1", 1).getString("enn2", "");
final String famaany = getSharedPreferences("faa1", 1).getString("faa2", "");
final int id = getSharedPreferences("id1", 1).getInt("id2", 1);

tt.setText(enmaany);
ttt.setText(famaany);       

我的活动1布局:

<?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"
        android:padding="5dp"
        android:background="@drawable/background_word">

        <LinearLayout
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:orientation="horizontal"
            android:id="@+id/arabic_et">

            <ImageView
                android:layout_height="40dp"
                android:layout_width="40dp"
                android:gravity="center"
                android:id="@+id/bSearchEn"
                android:src="@drawable/search_edit"
                android:background="@drawable/search_selector"/>

            <EditText
                android:inputType="text|textNoSuggestions"
                android:layout_height="match_parent"
                android:ems="10"
                android:layout_width="match_parent"
                android:id="@+id/inputSearchEn"
                android:background="#FFFFFF"
                android:textSize="20dp"
                android:gravity="center_vertical|start"
                android:hint="@string/searchEn"
                android:textStyle="bold"
                android:layout_marginLeft="10dp"/>

        </LinearLayout>

        <LinearLayout
            android:layout_height="match_parent"
            android:layout_width="match_parent"
            android:id="@+id/arabic_list"
            android:layout_marginTop="5dp"
            android:orientation="vertical">

            <ListView
                android:scrollbarSize="10dp"
                android:scrollbarThumbVertical="@drawable/custom_scroll_style"
                android:fastScrollEnabled="false"
                android:divider="#88D4D4D4"
                android:dividerHeight="1dp"
                android:layout_height="wrap_content"
                android:layout_width="match_parent"
                android:id="@+id/enlist"/>

            <ListView
                android:scrollbarSize="10dp"
                android:scrollbarThumbVertical="@drawable/custom_scroll_style"
                android:fastScrollEnabled="false"
                android:divider="#88D4D4D4"
                android:dividerHeight="1dp"
                android:layout_height="wrap_content"
                android:layout_width="match_parent"
                android:id="@+id/enlist2"/>

        </LinearLayout>

</LinearLayout>

我的活动2布局:

    <?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"
        android:background="#FFFFFF"
        android:id="@+id/lf"
        android:gravity="right">

        <LinearLayout
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:orientation="horizontal"
            android:weightSum="1.0">

            <LinearLayout
                android:layout_height="wrap_content"
                android:layout_width="match_parent"
                android:layout_weight=".5"
                android:gravity="left|center_vertical">

                <ImageView
                    android:layout_width="40dp"
                    android:gravity="center"
                    android:id="@+id/fa_img"
                    android:layout_height="40dp"
                    android:padding="3dp"/>

                <ImageView
                    android:layout_height="33dp"
                    android:layout_width="33dp"
                    android:background="@drawable/email_selector"
                    android:id="@+id/pronounce"/>

                <ImageView
                    android:layout_height="40dp"
                    android:layout_width="40dp"
                    android:id="@+id/copy"
                    android:src="@drawable/copy_selector"/>

            </LinearLayout>

            <LinearLayout
                android:layout_height="wrap_content"
                android:layout_width="match_parent"
                android:layout_weight=".5"
                android:gravity="right">

                <ImageView
                    android:layout_height="40dp"
                    android:layout_width="40dp"
                    android:src="@drawable/unlearn"
                    android:id="@+id/img_close"/>

            </LinearLayout>

        </LinearLayout>

        <View
            android:layout_height="1dp"
            android:layout_width="match_parent"
            android:background="#88D4D4D4"
            android:layout_marginTop="5dp"/>

        <ScrollView
            android:scrollbars="none"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:layout_marginTop="5dp">

            <LinearLayout
                android:layout_height="match_parent"
                android:layout_width="match_parent"
                android:orientation="vertical"
                android:gravity="center">

                <TextView
                    android:layout_height="match_parent"
                    android:textAppearance="?android:attr/textAppearanceLarge"
                    android:layout_width="match_parent"
                    android:id="@+id/tv_help"
                    android:gravity="center"
                    android:textColor="@color/c1"
                    android:textSize="25dp"
                    android:textStyle="bold"
                    android:typeface="monospace"/>

                <com.mshrapps.bs.ArialMTBoldRegularTextView2
                    android:layout_height="match_parent"
                    android:textAppearance="?android:attr/textAppearanceLarge"
                    android:layout_width="match_parent"
                    android:id="@+id/tv_fa"
                    android:gravity="right"
                    android:textColor="@color/c1"
                    android:textSize="20dp"
                    android:layout_marginTop="10dp"/>

            </LinearLayout>

        </ScrollView>

    </LinearLayout>

1 个答案:

答案 0 :(得分:0)

尝试将其添加到xml文件中的TextView

  android:singleLine="false"