Java cardView外部的文本视图

Java cardView外部的文本视图,java,android,layout,textview,Java,Android,Layout,Textview,我想将oldTextView的功能切换到ID为NameLabel的TextView “nameAgeLabel”位于视图之外。 它还应该像现在一样动态更改文本,具体取决于当前加载的视图 public View getView(final int position, View View, ViewGroup parent) { Log.d("position:",String.valueOf(position)); Log.d("laenge user id",String.v

我想将oldTextView的功能切换到ID为NameLabel的TextView

“nameAgeLabel”位于视图之外。 它还应该像现在一样动态更改文本,具体取决于当前加载的视图

public View getView(final int position, View View, ViewGroup parent) {


    Log.d("position:",String.valueOf(position));
    Log.d("laenge user id",String.valueOf(userIds.size()));

    String currentUserId = userIds.get(position);
    LayoutInflater inflater = (LayoutInflater)context.getSystemService
            (Context.LAYOUT_INFLATER_SERVICE);

View view = inflater.inflate(R.layout.content_single_mode_vc, parent, false);

    ImageView imageView = (ImageView) view.findViewById(R.id.offer_image);
    Bitmap image = userImages.get(currentUserId);
    imageView.setImageBitmap(image);


 TextView oldTextView= (TextView) view.findViewById(R.id.textView2);
 oldTextView.setText(userNames.get(currentUserId));
   //works fine

    return view;
}
我的onCreate如下所示:

  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_single_mode_vc);
    TextView nameAge = (TextView) findViewById(R.id.nameAgeLabel);

    updateImage();
    //(thats another method)

}
acvivity_single_mode_vc.xml:

<?xml version="1.0" encoding="utf-8"?>
<com.daprlabs.aaron.swipedeck.layouts.SwipeFrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:swipedeck="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/swipeLayout"
    android:orientation="vertical"
    android:background="@color/white">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay"/>
<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    />
<com.daprlabs.aaron.swipedeck.SwipeDeck
    android:id="@+id/swipe_deck"
    android:layout_width="match_parent"
    android:layout_height="600dp"
    android:padding="20dp"
    android:layout_marginTop="60dp"
    swipedeck:max_visible="3"
    swipedeck:card_spacing="15dp"
    swipedeck:swipe_enabled="true" >

</com.daprlabs.aaron.swipedeck.SwipeDeck>
<Button
    android:id="@+id/close"
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:layout_marginBottom="50dp"
    android:layout_marginLeft="20dp"
    android:layout_gravity="bottom"
    android:elevation="1dp"
    android:background="@drawable/close"
    android:backgroundTint="@color/light" />

<Button
    android:id="@+id/check"
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:layout_marginBottom="50dp"
    android:layout_marginRight="20dp"
    android:layout_gravity="bottom|right"
    android:background="@drawable/check"
    android:backgroundTint="@color/light" />

<TextView

    android:layout_width="match_parent"
    android:padding="20dp"
    android:layout_marginLeft="20dp"
    android:layout_marginRight="20dp"
    android:layout_height="wrap_content"
    android:layout_marginTop="350dp"
    android:id="@+id/nameAgeLabel"
    android:background="@color/separator"
   />
</com.daprlabs.aaron.swipedeck.layouts.SwipeFrameLayout>
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/card_view"
    android:layout_gravity="center"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    card_view:cardCornerRadius="4dp"
    card_view:cardElevation="4dp"
    card_view:cardUseCompatPadding="true"
    android:layout_margin="8dp"
    android:gravity="center_horizontal"
    android:padding="25dp"
    android:clipChildren="true">

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

 <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
<ImageView
        android:id="@+id/offer_image"
        android:layout_width="match_parent"
        android:scaleType="centerCrop"
        android:adjustViewBounds="true"
        android:layout_height="200dp"/>
<TextView
        android:text="TextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_marginLeft="137dp"
        android:layout_marginStart="137dp"
        android:layout_marginTop="222dp"
        android:id="@+id/textView2"/>

</RelativeLayout>
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:gravity="center">
    <ImageView
        android:layout_weight="1"
        android:id="@+id/left_image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/offer_image"
        android:layout_centerHorizontal="true" />
    <ImageView
        android:layout_weight="1"
        android:id="@+id/right_image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/offer_image"
        android:layout_centerHorizontal="true" />
    </LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
不包括ID为“nameAgeLabel”的textView。在onCreate中这样做没有多大意义。 在我的getView中创建一个新视图也不起作用,因为我无法返回2个视图,此外,我会收到一条“android requestlayout unjuly..”消息

非常感谢

编辑:类名+构造函数

public class SwipeDeckAdapter extends BaseAdapter {
[...]
public SwipeDeckAdapter(LinkedList<String> data, Context context, LinkedList<String> userIds, Hashtable<String,String> userNames, Hashtable<String,String> userHashtags, Hashtable<String,Bitmap> userImages, Hashtable<String,ArrayList<String>> userAccepted) {
    this.data = data;
    this.context = context;
    this.userIds = userIds;
    this.userNames = userNames;
    this.userHashtags = userHashtags;
    this.userImages = userImages;
    this.userAccepted = userAccepted;
}
}
公共类SwipeDeckAdapter扩展BaseAdapter{
[...]
公共SwipeDeckAdapter(LinkedList数据、上下文上下文、LinkedList用户名、哈希表用户名、哈希表用户标签、哈希表用户图像、哈希表用户接受){
这个数据=数据;
this.context=上下文;
this.userIds=userIds;
this.userNames=用户名;
this.userHashtags=userHashtags;
this.userImages=userImages;
this.userAccepted=userAccepted;
}
}

由于您的描述不完整,我试着猜测

SwipeFrameLayout
创建一个适配器,从
活动
传递
文本视图
。在构造函数或单独的方法中

差不多

 public class CustomSwipeDeckAdapter extends SwipeDeckAdapter {

    private AppCompatTextView mNameAgeLabel;

    public SwipeDeckAdapter(List<String> data, Context context, AppCompatTextView textview) {
      mNameAgeLabel = textView;
      […]
    }

    public View getView(final int position, View View, ViewGroup parent) {
      […]
      mNameAgeLabel.setText();
    }
公共类CustomSwipeDeckAdapter扩展SwipeDeckAdapter{
私有AppCompatTextView mNameLabel;
公共SwipeDeckAdapter(列表数据、上下文上下文、AppCompatTextView textview){
mNameAgeLabel=textView;
[…]
}
公共视图getView(最终整数位置、视图视图、视图组父视图){
[…]
mNameAgeLabel.setText();
}

感谢您的快速响应。是的,我忘了添加SwipeDeckAdapter构造函数。我在第一篇文章中对其进行了编辑。您还错过了什么吗?我用构造函数尝试了它,但在修复了nullpointerexception之后,因为MNAMAGEGLabel为null,所以用户名仍然没有显示在我的MNAMAGEGLabel中。这可能不是AppCompatTextView中的上下文是否正确?
 public class CustomSwipeDeckAdapter extends SwipeDeckAdapter {

    private AppCompatTextView mNameAgeLabel;

    public SwipeDeckAdapter(List<String> data, Context context, AppCompatTextView textview) {
      mNameAgeLabel = textView;
      […]
    }

    public View getView(final int position, View View, ViewGroup parent) {
      […]
      mNameAgeLabel.setText();
    }