這裏我試圖添加一個圖像列表視圖和每個圖像上的文字。其實我試圖根據用戶輸入生成貼紙。 這是我的主要活動:如何添加圖像到可繪製的列表視圖
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageView im =(ImageView) findViewById(R.id.imageView1);
final EditText ed =(EditText) findViewById(R.id.editText1);
final TextView tx =(TextView) findViewById(R.id.textView1);
Button bt=(Button) findViewById(R.id.button1);
final Typeface custom_font = Typeface.createFromAsset(getAssets(), "font/d.ttf");
bt.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
String ts1 = ed.getText().toString();
tx.setText(ts1);
tx.setTypeface(custom_font);
}
});
}}
這是我的xml文件:
activity_main.xml中:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.shifn2.MainActivity" >
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:ems="10" >
<requestFocus />
</EditText>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/editText1"
android:layout_alignBottom="@+id/editText1"
android:layout_toRightOf="@+id/editText1"
android:text="Button" />
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/button1" >
</ListView>
</RelativeLayout>
list.xml
<?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" >
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textSize="30sp"
android:text="Large Text"
android:textColor="#FF0000"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/confidential" />
</FrameLayout>
</LinearLayout>
請幫我做一個listview。任何幫助都是可以欣賞的。謝謝
哪裏是ListView和適配器的代碼? – 2014-12-03 06:37:42
我需要適配器代碼..即時新到android – 2014-12-03 06:45:29
可以請你幫我嗎? – 2014-12-03 06:46:05