Textview不在Intent上显示

时间:2015-03-14 15:36:15

标签: android

该应用程序应该接收一个字符串拆分它并显示卡上的第一部分。然而,它似乎被设置为空值,我无法弄清楚为什么。

这是我的活动类

package apps.jp.flashstacks;

import android.graphics.Typeface;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.*;

import java.util.ArrayList;


public class FrontCard extends ActionBarActivity {

private final String TAG = "FRONT CARDS";

ArrayList<String> cards;
int i;
TextView tv;
String backText;

private String parseFront(String s){
    String[] cardTexts = s.split("|||");
    String s1 = cardTexts[0];
    Log.v(TAG, cardTexts[0] + " , " + cardTexts[1]);
    this.backText = cardTexts[1];
    return s1;
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_front_card);
    Bundle b = this.getIntent().getExtras();
    this.cards = b.getStringArrayList("cards");
    Log.v(TAG, ""+cards.size() + " , " + cards.get(0));
    this.i = b.getInt("Loc");
    Log.v(TAG, "i:"+i);
    this.tv = (TextView)findViewById(R.id.Front_Card_Text);
    Typeface font = Typeface.createFromAsset(getAssets(), "Booklet Cordel.ttf");
    this.tv.setTypeface(font);
    String fText = parseFront(cards.get(i));
    Log.v(TAG, fText);
    this.tv.setText(fText);

}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_front_card, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
    }
}

这是XML文件

<RelativeLayout 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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="apps.jp.flashstacks.FrontCard"
android:background="@drawable/card_background">

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:text="@string/front_card_text"
    android:id="@+id/Front_Card_Text"
    android:layout_centerVertical="true"
    android:layout_centerHorizontal="true"
    android:textSize="42sp" />

</RelativeLayout>

0 个答案:

没有答案