简体   繁体   中英

Why my textview is show in single line when I start the app firstly?

I have a very wonderful problem in my app. I have a text view in my activity which get a text from sqlite like this:

Hello

World!

But when I start my app for first time, My text view show the text like this:

Hello word!

When I go out from app and clear my app form RAM and then comeback to the app my text view show the text currectly like this:

Hello

World!

In fact, when onCreate method run for first time my text view text show in single line. I tried very ways like use recreate method:

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

And in onCreate method:

recreate();

But my app crashed! Is there a way to solve this problem? Thanks

My Ativity1:

   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();
}});

My Activity 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);       

My activity 1 layout:

<?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>

My activity 2 layout:

    <?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>

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

  android:singleLine="false" 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM