亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

將卡片視圖放入片段內

將卡片視圖放入片段內

明月笑刀無情 2023-08-16 10:21:25
我使用幾個片段制作了一個選項卡菜單。我將在每個片段中放置一個卡片視圖。我嘗試過谷歌搜索,但我所要做的就是將卡片視圖放入活動中。我想在片段中放置一個卡片視圖,然后我想在單擊卡片時實現預定義集活動的啟動。我能怎么做?我參考了https://www.codingdemos.com/android-tablayout-example-viewpager來查看選項卡菜單。我附上我的片段布局(xml 文件)代碼<FrameLayout 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"  tools:context="com.aeyoung.csw.CommunityFragment">  <!-- TODO: Update blank fragment layout -->  <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"      xmlns:app="http://schemas.android.com/apk/res-auto"      xmlns:tools="http://schemas.android.com/tools"      android:layout_width="match_parent"      android:layout_height="match_parent"      tools:context="com.aeyoung.csw.CommunityFragment">    <android.support.v7.widget.RecyclerView        android:id="@+id/list"        android:layout_width="match_parent"        android:layout_height="wrap_content">    </android.support.v7.widget.RecyclerView>  </android.support.constraint.ConstraintLayout></FrameLayout>我還添加了片段代碼(java文件)import android.os.Bundle;import android.support.v7.app.AppCompatActivity;import android.support.v7.widget.LinearLayoutManager;import android.support.v7.widget.RecyclerView;import java.util.ArrayList;import java.util.List;public class CommunityFragment extends AppCompatActivity {    //Create parameter    List<Product> productList = new ArrayList<>();    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.fragment_community);        // initialize parameter "productList"        setInitialData();        //Find RecyclerView from fragment_community.xml        RecyclerView recyclerView = (RecyclerView) findViewById(R.id.list);        // Create LinearLayoutManager and set it to RecyclerView        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);    }
查看完整描述

1 回答

?
慕村225694

TA貢獻1880條經驗 獲得超4個贊

因為錯誤告訴您"error: incompatible types: CommunityFragment cannot be converted to Fragment" 您的 CommunityFragment 擴展了AppCompatActivity并且它不是片段。



查看完整回答
反對 回復 2023-08-16
  • 1 回答
  • 0 關注
  • 118 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號