1.我想更改listView中项目的textSize。
我有一个带有按钮和片段布局中的listView的xml文件。
我无法更改文本项目的大小。
我试过,在xml,android:textSize,我在这里搜索,但问题是不一样的,因为通常他们没有活动内部的按钮(在我的情况下,一个片段)。
My onResume with ArrayAdapter
public void onResume()
{
super.onResume();
ListView listaDeEquipas=(ListView)getView().findViewById(R.id.listaEquipas);
final ArrayAdapter<Equipa> itemsAdapter = new ArrayAdapter<Equipa>(getActivity(), android.R.layout.simple_list_item_1, listaEquipas);
listaDeEquipas.setAdapter(itemsAdapter);
itemsAdapter.notifyDataSetChanged();
listaDeEquipas.setOnItemLongClickListener(new OnItemLongClickListener(){
public boolean onItemLongClick(AdapterView<?> adapterView, View view, int position, long id) {
listaEquipas.remove(position);
itemsAdapter.notifyDataSetChanged();
return false;
}
});
}
My xml code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<Button
android:id="@+id/addEquipa"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:padding="20dip"
android:textColor="#ffffffff"
android:background="#FFCC0000"
android:textStyle="bold"
android:textSize="40sp"
android:text="Inserir Equipa"
android:onClick="true"/>
<ListView
android:id="@+id/listaEquipas"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="10dp"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:layout_gravity="center"
android:fastScrollEnabled="true">
</ListView>
</LinearLayout>
答案 0 :(得分:0)
在ListView适配器中,将此行放在getView()
:
TextView text = (TextView) v.findViewById(android.R.id.text1);
text.setTextSize(30);
您可能需要为ListView实现自定义适配器,如下所示:
package de.vogella.android.listactivity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
public class myArrayAdapter extends ArrayAdapter<Equipa> {
private final Context context;
private final Equipa[] values;
public myArrayAdapter(Context context,Equipa[] values) {
super(context, android.R.layout.simple_list_item_1, values);
this.context = context;
this.values = values;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(android.R.layout.simple_list_item_1, parent, false);
TextView text = (TextView) rowView.findViewById(android.R.id.text1);
text.setTextSize(30);
textView.setText(values[position]); // Set what you want the text to be here
return rowView;
}
}