MainActivity.java
package android.com.listusingscrollbar; import android.content.Context; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.LayoutInflater; import android.view.View; import android.widget.LinearLayout; import android.widget.TextView; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); LinearLayout linearLayout= (LinearLayout) findViewById(R.id.linearLayout); LayoutInflater inflater= (LayoutInflater) getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); String[] data={"Android","Java","Php","Dot net","Ios","Lenovo","Logitech","Android","Java","Php","Dot net","Ios","Lenovo","Logitech"}; for(int i=0; i<data.length;i++) { View v=inflater.inflate(R.layout.item,null); TextView tv = (TextView) v.findViewById(R.id.list_item); tv.setText(data[i]); linearLayout.addView(tv); } } }
LAYOUTS
activity_main.xml
<?xml version="1.0" encoding="utf-8"?> <ScrollView android:id="@+id/scrollView" android:layout_height="match_parent" android:layout_width="match_parent" xmlns:android="http://schemas.android.com/apk/res/android"> <LinearLayout android:id="@+id/linearLayout" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> </LinearLayout> </ScrollView>
item.xml
<?xml version="1.0" encoding="utf-8"?> <TextView android:id="@+id/list_item" android:layout_height="wrap_content" android:layout_width="match_parent" android:layout_margin="16sp" android:textColor="@color/listColor" android:gravity="center" android:textSize="30sp" android:text="hello" xmlns:android="http://schemas.android.com/apk/res/android" />
0 comments:
Post a Comment