Hii
I was coding for an application that shows the list of running process and i was using TextView to display the running process in screen. I was trying 2 different method for displaying the TextView. In one method i was declearing the TextView in the code itself
TextView tv = new TextView(this);
this.setContentView(tv);
In the second method i was declearing the layout in the main.xml file
setContentView(R.layout.main);
TextView tv=(TextView) findViewById(R.id.RunApp);
For both the methods i am using the setMovementMethod for having the scroll movement for my TextView
tv.setMovementMethod(new ScrollingMovementMethod());
The program is running fine in the emulator.But if i am using the second method then the scrolling is not happening if i am running the application in my mobile. In the emulator its working fine. Why is it behaving differently in my Android 2.1 Samsung Galaxy S?? Why the scrolling not happening in the second method??. Scrolling is happening in the first method without any issues in my mobile.
This is my code..
public class listRunningApps extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.main);
//TextView tv=(TextView) findViewById(R.id.RunApp);
TextView tv = new TextView(this);
this.setContentView(tv);
tv.setMovementMethod(new ScrollingMovementMethod());
ActivityManager actvityManager = (ActivityManager)
this.getSystemService( ACTIVITY_SERVICE );
List<RunningAppProcessInfo> procInfos = actvityManager.getRunningAppProcesses();
for(int j=0; j < 2; j++)
/*I have done iteration 2 times so that we have a long process list
sufficeint enough for scrolling*/
{
for(int i = 0; i < procInfos.size(); i++)
{
tv.setText(tv.getText().toString()+procInfos.get(i).processName+
" " + String.valueOf(procInfos.get(i).processName.length())+"\n");
}
tv.setText(tv.getText().toString()+"----------------------------"+"\n");
}
}
}
This is my main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/jsttxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Testing TextView Scrolling"/>
<TextView
android:id="@+id/RunApp"
android:layout_marginLeft="30px"
android:layout_marginRight="30px"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/jsttxt"
/>
</RelativeLayout>
In the first method the scrolling is coming in my mobile without any issue..Can you guys help me why the scrolling is not happening in my mobile in the second method, where as its working properly in my emulator??