0

今天早上,我遇到了一些关于 Eclipse 的问题,以及它的常见错误,即 R 无法重新生成。在我解决它之后,我写了很多新的包,所以恢复到最后一个工作提交不是一个选项,我现在是 17:00...

这是我的代码:

@Override
protected void onCreate(Bundle savedInstanceState) {
    mActivity = this;
    super.onCreate(savedInstanceState);
    contentView = getLayoutInflater().inflate(R.layout.android_messenger_conversation, null);
    setContentView(contentView);
}


@Override
protected void onStart() {
    super.onStart();
    Bundle extras = getIntent().getExtras();
    if(extras != null){
        Log.i("ConversationActivity/onStart","extras is not null");
        String extra = extras.getString(MainActivity.CONVERSATION_EXTRA);
        Log.i("ConversationActivity/onStart","got extra gave value: "+extra);
        if(extra!=withWhoWeAreChatting){
            withWhoWeAreChatting = extra;
        }
        ArrayList<ConversationInfo> arrayList = Conversation.getConversationWith(getApplicationContext(), extra);

        contentView = getLayoutInflater().inflate(R.layout.android_messenger_conversation, null);
        LinearLayout linearLayout = (LinearLayout) contentView.findViewById(R.id.android_messgener_conversation_LinearLayout);
        for(int i = arrayList.size()-1 ; i >= 0 ; i--){
            Log.i("ConversationActivity/onStart","Doing for loop: "+i);
            ConversationInfo conversationInfo = arrayList.get(i);
            if(conversationInfo.getProtocol()!=null){
                RelativeLayout relativeLayout = (RelativeLayout) getLayoutInflater().inflate(R.layout.android_messenger_inbox_message, null);
                TextView inbox_message = (TextView)relativeLayout.findViewById(R.id.inbox_message);
                inbox_message.setText(conversationInfo.getBody());

                linearLayout.addView(relativeLayout);
            }
            else{
                RelativeLayout relativeLayout = (RelativeLayout) getLayoutInflater().inflate(R.layout.android_messenger_sent_message, null);
                TextView inbox_message = (TextView)relativeLayout.findViewById(R.id.sentMessage);
                inbox_message.setText(conversationInfo.getBody());

                linearLayout.addView(relativeLayout);
            }
        }
        setContentView(contentView);
    }
}

setContentView(contentView) 就在我的评论上方,并没有改变任何东西。通过日志,我检查了循环内的所有内容都没有错误地执行。

有任何想法吗?

如果你住在欧洲,我可以邮寄给你一些波兰啤酒 :)

干杯

4

1 回答 1

1

给大家添麻烦了:)

正如我所提到的,我从早上起就没有改变任何东西。但我将我的 xml 文件更改为滚动视图。

由此:

        <LinearLayout
        android:id="@+id/android_messgener_conversation_LinearLayout"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

    </LinearLayout>

对此:

        <LinearLayout
        android:id="@+id/android_messgener_conversation_LinearLayout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

    </LinearLayout>

恢复这个解决了我的问题:)现在它几乎就像一个魅力:)

再次抱歉给您添麻烦了!

并为用户 user1455909 欢呼——当我遇到任何类型的错误时,清理和重建是我的基本操作:D

于 2013-07-01T15:58:46.530 回答