TextView.settext() не работает, Button.settext() работает хорошо

Я работал над классом, который использует Runtime.exec и получает его вывод, однако он был не очень стабилен... Теперь я использовал этот класс, чтобы получить вывод команды "ls/sdcard/" (зная, что у меня есть нужные разрешения в моем манифесте)... (ниже напишу коды) Моя проблема в том, что вывод Text из команды может отображаться как Toast, и его можно задать как текст для кнопки, но не текст для текстовое представление! когда я запускаю свой TextView.settext() , TextView вообще не отображает текст! Что еще более странно, так это то, что если я использую settext() как TextView.settext("Hey there , I am reset");, он работает и показывает этот текст! Вот коды:

MainActivity.class/Button.setOnClickListener:

B1.setOnClickListener(new View.OnClickListener() {          
    public void onClick(View arg0) {
        String sdcard = File.separator+Environment.getExternalStorageDirectory().toString()+File.separator; //unused
        String[] arr = {"ls" , "/sdcard/..ROMS/"};//unused - was for experimentation
        String r = shell.sendSingleCommand("ls /sdcard/"); //"r" should now hold the output (stdin and stderr) of the command - shell is defined as Shells shell = new Shells();
        B3.setText(r); //Text of the button changes to the String r
        text.setText(r); //Text is blank , no text is shown at all , not even what it originally was - "text" is my TextView ... Here's my problem
        Show(r); // a method that shows a Toast for a given String - shows the String r normally in a normal Toast ...

    }
});

Объявления большинства переменных в MainActivity:

        final Button B1 = (Button) findViewById(R.id.button1);
        final Button B2 = (Button) findViewById(R.id.button2);
        final Button B3 = (Button) findViewById(R.id.button3);
        final SharedPreferences pref = getSharedPreferences("seaskyways.testingproject",0);     
        final TextView text = (TextView) findViewById(R.id.testing_text_view);
        final Shells shell = Shells.Shells(); //which returns new Shells()

Макет/activity_main.xml:

<ScrollView xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:layout_marginLeft="37dp"
            android:text="Button 1" />

        <Button
            android:id="@+id/button2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:layout_marginRight="52dp"
            android:text="Button 2" />

        <Button
            android:id="@+id/button3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/button1"
            android:layout_centerHorizontal="true"
            android:text="Button 3" />

        <ScrollView
            android:id="@+id/scrollView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentRight="true"
            android:layout_below="@+id/button3" >

            <TextView
                android:id="@+id/testing_text_view"
                android:layout_width="222dp"
                android:layout_height="236dp"
                android:gravity="center|top"
                android:padding="10sp"
                android:text="Hey there !"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:textColor="@color/abs__primary_text_holo_dark" />

        </ScrollView>
</RelativeLayout>
</ScrollView>

Показать() :

public void Show(String a){
    Toast.makeText(getApplicationContext(),a , Toast.LENGTH_SHORT).show();
}

Shells.class/sendSingleCommand():

public String sendSingleCommand(String singlecmd) { 
    String a = "";
    final BufferedReader in ;
    final BufferedReader er;

    final String r;

        try {
            p = Runtime.getRuntime().exec(singlecmd);           
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    in = new BufferedReader(new InputStreamReader(p.getInputStream()));
    er = new BufferedReader(new InputStreamReader(p.getErrorStream()));
    try{
        String n;

        while((n = er.readLine())!=null){
            a = a + n + "\n";
        }

        while((n=in.readLine())!=null){
            a = a +"\n"+ n;
            while((n = er.readLine())!=null){
                a = a +"\n"+ n;
            }
        }
    }catch(Exception e){
        e.printStackTrace();
    }
    p.destroy();
    try {
        in.close();
        er.close();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    final StringBuilder build = new StringBuilder();
    build.append(a);
    if(a.startsWith("null")){
        build.substring(4);
    }
    a= build.toString();
    return a;
}

AndroidManifest.xml (в случае необходимости):

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="seaskyways.testingproject"
    android:versionCode="1"
    android:versionName="beta" >

    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="17" />
    <uses-permission 
        android:name="android.permission.READ_EXTERNAL_STORAGE"
        />

    <application
        android:allowBackup="true"

        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/Theme.Sherlock" >
        <activity
            android:name="seaskyways.testingproject.MainActivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.Holo" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="seaskyways.testingproject.MenuActivity"
            android:label="@string/title_activity_menu" >
        </activity>
        <activity
            android:name="seaskyways.testingproject.Splash"
            android:label="@string/title_activity_splash" android:theme="@style/Theme.Sherlock.Dialog" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name="seaskyways.testingproject.HorizontalScrollView"
            android:label="@string/title_activity_splash" >
            <intent-filter>
                <action android:name="android.intent.action.HSV" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
    </application>

</manifest>

если вам нужно что-то узнать в комментариях, пожалуйста!


person Seaskyways    schedule 16.01.2013    source источник
comment
Расскажите нам, где вы объявили свой TextView и как вы это сделали.   -  person Marckaraujo    schedule 17.01.2013
comment
Вот и все, добавлены все необходимые объявления и макет, используемый MainActivity!   -  person Seaskyways    schedule 17.01.2013
comment
См. android:textColor=@color/abs__primary_text_holo_dark, проверьте его, возможно, это тот же цвет, что и ваш фон.   -  person Marckaraujo    schedule 17.01.2013
comment
Я добавил это, чтобы я мог убедиться, что цвет виден, а не как фон, нет, это не так ...   -  person Seaskyways    schedule 17.01.2013


Ответы (1)


ScrollView может содержать только один прямой дочерний элемент

Попробуйте использовать этот макет: измените имена, которые вы используете, и попробуйте.

<?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:layout_width="match_parent"
        android:layout_height="match_parent" >

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="138dp" >

            <Button
                android:id="@+id/button1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button" />

            <Button
                android:id="@+id/button2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_alignParentTop="true"
                android:layout_marginLeft="104dp"
                android:text="Button" />

            <Button
                android:id="@+id/button3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_alignParentTop="true"
                android:layout_marginRight="43dp"
                android:text="Button" />

            <ScrollView
                android:id="@+id/scrollView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="50dp"
                android:layout_marginTop="50dp" >

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" >

                    <TextView
                        android:id="@+id/textView1"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="TextView" />

                </LinearLayout>
            </ScrollView>

        </RelativeLayout>

    </LinearLayout>


</ScrollView>
person Marckaraujo    schedule 17.01.2013
comment
Спасибо , как раз то что нужно , но этот макет как то странно выглядит , поправлю вид , спасибо большое ! - person Seaskyways; 17.01.2013