我现在正在学习很多关于stackoverflow的帖子,在使用eclipse进行java编程时我已经完全怀疑了,但是我开始制作自定义代码并且我陷入困境,我在代码上创建了一个可点击的列表视图我想改变项目的文字大小并对齐listview布局,任何提示?
Obs。:我只有1项可用代码,这是一个实验。
提前致谢
package com.example.aulasinterativas;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
public class Menu extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
try {
setContentView(R.layout.menu);
ListView mlistView = (ListView) findViewById(R.id.listView1);
mlistView.setAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, new String[] {
"Infantil", "1° ano", "2° ano", "3° ano", "4° ano",
"5° ano", "6° ano", "7° ano", "8° ano", "9° ano",
"1° ano do Ensino Médio", "2° ano do Ensino Médio", "3° ano do Ensino Médio" }));
mlistView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Toast.makeText(getApplicationContext(),
((TextView) view).getText(), Toast.LENGTH_SHORT)
.show();
String sText = ((TextView) view).getText().toString();
Intent intent = null;
if (sText.equals("1° ano"))
intent = new Intent(getBaseContext(), Menu1ano.class);
if (intent != null)
startActivity(intent);
}
});
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
我的XML文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:background="@drawable/tile"
android:orientation="vertical" >
<ListView
android:id="@+id/listView1"
android:layout_width="wrap_content"
android:layout_height="357dp"
android:gravity="center_horizontal"
</ListView>
</LinearLayout>