Tengo un adaptador personalizado en el que inflo el diseño. En adaptador i tratar de cambiar algún valor de texto en TextView (@ id/datetextcal)Cambiar el valor del texto en el diseño de inflar
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
cellView = inflater.inflate(R.layout.calendarcell, null);
TextView dateText = (TextView) cellView.findViewById(R.id.datetextcal);
dateText.setText(position);
creo que está bien, pero tengo un error! por qué ?
Sin modificar este valor, todas las compilaciones y el trabajo son correctos.
código de diseño (R.layout.calendarcell):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:background="@drawable/cell"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="40dp"
android:layout_height="40dp">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical">
<TextView
android:id="@+id/datetextcal"
android:text="2"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<ImageView
android:layout_alignRight="@id/datetextcal"
android:paddingRight="2dp"
android:src="@drawable/dropper"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
<TextView
android:gravity="center_horizontal"
android:textSize="9dp"
android:text="заметка"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
código para la clase de adaptador:
package com.android.wcalendar;
import java.util.Date;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
public class ImageAdapter extends BaseAdapter
{
private static final String TAG = "trace";
private Context mContext;
public ImageAdapter(Context c)
{
// TODO Auto-generated constructor stub
mContext = c;
}
@Override
public int getCount()
{
// TODO Auto-generated method stub
return 7 * 5;
}
@Override
public Object getItem(int arg0)
{
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int arg0)
{
// TODO Auto-generated method stub
return 0;
}
@Override
// create a new ImageView for each item referenced by the Adapter
public View getView(int position, View convertView, ViewGroup parent)
{
View cellView = convertView;
if (cellView == null)
{ // if it's not recycled, initialize some attributes
cellView = new View(mContext);
Log.d(TAG, "cellView null");
} else
{
Log.d(TAG, "cellView not null");
cellView = (View) convertView;
}
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
cellView = inflater.inflate(R.layout.calendarcell, null);
// Date date = new Date();
// date.setDate(position);
TextView dateText = (TextView)
cellView.findViewById(R.id.datetextcal);
dateText.setText(position);
return cellView;
}
}
y que los errores:
02-03 11:58:45.774: ERROR/AndroidRuntime(286): Uncaught handler: thread main exiting due to uncaught exception
02-03 11:58:45.845: ERROR/AndroidRuntime(286): android.content.res.Resources$NotFoundException: String resource ID #0x0
02-03 11:58:45.845: ERROR/AndroidRuntime(286): at android.content.res.Resources.getText(Resources.java:200)
02-03 11:58:45.845: ERROR/AndroidRuntime(286): at android.widget.TextView.setText(TextView.java:2813)
02-03 11:58:45.845: ERROR/AndroidRuntime(286): at com.android.wcalendar.ImageAdapter.getView(ImageAdapter.java:67)
02-03 11:58:45.845: ERROR/AndroidRuntime(286): at android.widget.AbsListView.obtainView(AbsListView.java:1274)
02-03 11:58:45.845: ERROR/AndroidRuntime(286): at android.widget.GridView.onMeasure(GridView.java:934)
02-03 11:58:45.845: ERROR/AndroidRuntime(286): at android.view.View.measure(View.java:7964)
02-03 11:58:45.845: ERROR/AndroidRuntime(286): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3023)
02-03 11:58:45.845: ERROR/AndroidRuntime(286): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:888)
02-03 11:58:45.845: ERROR/AndroidRuntime(286): at android.widget.LinearLayout.measureVertical(LinearLayout.java:350)
02-03 11:58:45.845: ERROR/AndroidRuntime(286): at android.widget.LinearLayout.onMeasure(LinearLayout.java:278)
02-03 11:58:45.845: ERROR/AndroidRuntime(286): at android.view.View.measure(View.java:7964)
02-03 11:58:45.845: ERROR/AndroidRuntime(286): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3023)
02-03 11:58:45.845: ERROR/AndroidRuntime(286): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:888)
02-03 11:58:45.845: ERROR/AndroidRuntime(286): at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:619)
02-03 11:58:45.845: ERROR/AndroidRuntime(286): at android.widget.LinearLayout.onMeasure(LinearLayout.java:280)
02-03 11:58:45.845: ERROR/AndroidRuntime(286): at android.view.View.measure(View.java:7964)
02-03 11:58:45.845: ERROR/AndroidRuntime(286): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3023)
02-03 11:58:45.845: ERROR/AndroidRuntime(286): at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
02-03 11:58:45.845: ERROR/AndroidRuntime(286): at android.view.View.measure(View.java:7964)
02-03 11:58:45.845: ERROR/AndroidRuntime(286): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3023)
02-03 11:58:45.845: ERROR/AndroidRuntime(286): at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
02-03 11:58:45.845: ERROR/AndroidRuntime(286): at android.view.View.measure(View.java:7964)
02-03 11:58:45.845: ERROR/AndroidRuntime(286): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3023)
02-03 11:58:45.845: ERROR/AndroidRuntime(286): at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
02-03 11:58:45.845: ERROR/AndroidRuntime(286): at android.view.View.measure(View.java:7964)
02-03 11:58:45.845: ERROR/AndroidRuntime(286): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3023)
02-03 11:58:45.845: ERROR/AndroidRuntime(286): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:888)
02-03 11:58:45.845: ERROR/AndroidRuntime(286): at android.widget.LinearLayout.measureVertical(LinearLayout.java:350)
02-03 11:58:45.845: ERROR/AndroidRuntime(286): at android.widget.LinearLayout.onMeasure(LinearLayout.java:278)
02-03 11:58:45.845: ERROR/AndroidRuntime(286): at android.view.View.measure(View.java:7964)
02-03 11:58:45.845: ERROR/AndroidRuntime(286): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3023)
02-03 11:58:45.845: ERROR/AndroidRuntime(286): at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
02-03 11:58:45.845: ERROR/AndroidRuntime(286): at android.view.View.measure(View.java:7964)
02-03 11:58:45.845: ERROR/AndroidRuntime(286): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3023)
02-03 11:58:45.845: ERROR/AndroidRuntime(286): at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
02-03 11:58:45.845: ERROR/AndroidRuntime(286): at android.view.View.measure(View.java:7964)
02-03 11:58:45.845: ERROR/AndroidRuntime(286): at android.widget.LinearLayout.measureVertical(LinearLayout.java:464)
02-03 11:58:45.845: ERROR/AndroidRuntime(286): at android.widget.LinearLayout.onMeasure(LinearLayout.java:278)
02-03 11:58:45.845: ERROR/AndroidRuntime(286): at android.view.View.measure(View.java:7964)
02-03 11:58:45.845: ERROR/AndroidRuntime(286): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3023)
02-03 11:58:45.845: ERROR/AndroidRuntime(286): at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
02-03 11:58:45.845: ERROR/AndroidRuntime(286): at android.view.View.measure(View.java:7964)
02-03 11:58:45.845: ERROR/AndroidRuntime(286): at android.view.ViewRoot.performTraversals(ViewRoot.java:763)
02-03 11:58:45.845: ERROR/AndroidRuntime(286): at android.view.ViewRoot.handleMessage(ViewRoot.java:1633)
02-03 11:58:45.845: ERROR/AndroidRuntime(286): at android.os.Handler.dispatchMessage(Handler.java:99)
02-03 11:58:45.845: ERROR/AndroidRuntime(286): at android.os.Looper.loop(Looper.java:123)
02-03 11:58:45.845: ERROR/AndroidRuntime(286): at android.app.ActivityThread.main(ActivityThread.java:4363)
02-03 11:58:45.845: ERROR/AndroidRuntime(286): at java.lang.reflect.Method.invokeNative(Native Method)
02-03 11:58:45.845: ERROR/AndroidRuntime(286): at java.lang.reflect.Method.invoke(Method.java:521)
02-03 11:58:45.845: ERROR/AndroidRuntime(286): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
02-03 11:58:45.845: ERROR/AndroidRuntime(286): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
02-03 11:58:45.845: ERROR/AndroidRuntime(286): at dalvik.system.NativeStart.main(Native Method)
es cierto. gracias – Hawkins
@Hawkings - De nada. –
Holy Cow acaba de pasar 20 minutos en este mismo tema y se dio cuenta de que era porque estaba pasando un int en lugar de un texto como este problema. – JPM