0

我有一个在片段中单击 listView 项目时调用的 Activity。我的问题是,即使我对布局进行了更改(设置 textviews 的文本等)并调用 setContentView,活动屏幕仍然是空白的。

从到处使用的 Log.i 中,在 logcat 中,我可以看到所有数据并且它被正确设置,所以这不是问题。

我的问题是如何做到这一点,以便我所做的更改显示在屏幕上/如何使用新数据刷新布局。

public class SemListViewActivity extends Activity
{
    JSONObject recdJson=new JSONObject();
    JSONArray ar;
    ArrayList<HashMap<String, String>> keyslist;
    TextView semTCredits, semSession, semGPA;
    ListView semList;
    SemListAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        Log.i("Info Tag Sem","Inside Sem");

        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.sem_details_listview_layout);

        //LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        //View v = inflater.inflate(R.layout.sem_details_listview_layout,null);

        ar = new JSONArray();
        keyslist = new ArrayList<HashMap<String, String>>();
        try
        {
            recdJson = GlobalVars.semJSON;
            Log.i("Info Tag Sem","Got the JSON");
            ar = recdJson.getJSONArray("seminfo");
            Log.i("Info Tag Sem","assigning JSON Array");
            for (int i = 0; i < ar.length(); i++)
            {
                JSONObject jObject = ar.getJSONObject(i);
                HashMap<String, String> map = new HashMap<String, String>();
                Log.i("Info Tag Sem","jObject Init"+i);
                Log.i("Info Tag Sem",jObject.toString());
                Log.i("Info Tag Sem",jObject.getString("subcode"));
                map.put("subcode", jObject.getString("subcode"));
                map.put("sub", jObject.getString("sub"));
                map.put("credits", jObject.getString("credits"));
                map.put("grade", jObject.getString("grade"));


                keyslist.add(map);
            }
            Log.i("Info Tag Sem","Done with Hashmapping");

            semTCredits = (TextView)findViewById(R.id.semTCredits);
            semSession = (TextView)findViewById(R.id.semSession);
            semGPA = (TextView)findViewById(R.id.semGPA);

            Log.i("Info Tag Sem","Set the textviews");

            semTCredits.setText("Total Credits: " + recdJson.getString("credits"));
            semSession.setText("Session: " + recdJson.getString("session"));
            semGPA.setText("Semester GPA: " + recdJson.getString("gpa"));



            semList = (ListView)findViewById(R.id.semlist);

            adapter = new SemListAdapter(this, keyslist);
            semList.setAdapter(adapter);

            Log.i("Info Tag Sem","Put the content");

            setContentView(R.layout.sem_details_listview_layout);

        } catch (JSONException e)
        {
            e.printStackTrace();
            Log.i("Info Tag Sem","Nothing happened ");
        }

    }

}

这是相关的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" >

    <TextView
        android:id="@+id/semTCredits"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:padding="5dp"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/semSession"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:padding="2dp"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textIsSelectable="true" />

    <TextView
        android:id="@+id/semGPA"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:padding="2dp"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textIsSelectable="true" />

    <ListView
        android:id="@+id/semlist"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
    </ListView>

</LinearLayout>

抱歉,如果这个问题是重复的,我不知道如何表达我的问题。

4

1 回答 1

0

你打setContentView()了两次电话,第二次打电话:

        Log.i("Info Tag Sem","Put the content");

        setContentView(R.layout.sem_details_listview_layout);

    } catch (JSONException e)

删除您在上面所做的所有更改...只需将其删除。

于 2013-04-13T16:58:31.427 回答