第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

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

如何從重新搜索視圖上打開新意向

如何從重新搜索視圖上打開新意向

ITMISS 2022-09-14 17:15:47
我仍然是Android開發(fā)的初學(xué)者,在我的rekylerview項目點擊后,我正在設(shè)置一些新視圖,但我的應(yīng)用程序在kotlin和android之間混合,因為我從互聯(lián)網(wǎng)上獲得了一些源代碼,但我的項目從一開始就是由kotlin編譯的。// Set New View Adapter// Based on Javaholder.itemImageView.setOnClickListener(new CustomOnItemClickListener(position, new CustomOnItemClickListener.OnItemClickCallback() {                @Override                public void onItemClicked(View view, int position) {                    if(holder.itemNameTextView.getText().equals("Pemerintahan (OPD)")){                        //open new intent                    else if(holder.itemNameTextView.getText().equals("Pelayanan Publik")){                       //open new intent                    }我引用的示例代碼被使用 kotlin 顯示像這樣開始的新活動// Referenced Code// Based on Kotlinclass MainActivity : AppCompatActivity() {    override fun onCreate(savedInstanceState: Bundle?) {        super.onCreate(savedInstanceState)        setContentView(R.layout.activity_main)        creativeViewPagerView.setCreativeViewPagerAdapter(NatureCreativePagerAdapter(this))    }}注意 : 創(chuàng)建視圖頁面視圖 = 是 xml 活動上的屬性值 主要性質(zhì)創(chuàng)意頁面適配器 = 是我將使用的適配器set創(chuàng)意查看頁面適配器 = 類中的一個函數(shù),代碼如下// setCreativeViewPagerAdapter\// Based on Kotlinfun setCreativeViewPagerAdapter(creativePagerAdapter: CreativePagerAdapter) {    post({      this.creativePagerAdapter = creativePagerAdapter      // Setup adapter for palette manager      paletteCacheManager.setCreativeViewAdapter(creativePagerAdapter)      paletteCacheManager.cachePalettesAroundPositionAsync(0, {        refreshBackgroundColor(0, 0f)      })    })  }我的問題是如何讓引用的示例代碼在我的//設(shè)置新視圖適配器上工作 非常感謝。
查看完整描述

3 回答

?
哈士奇WWW

TA貢獻1799條經(jīng)驗 獲得超6個贊

要創(chuàng)建一個新的,你只需要一個實例。您可以從以下任何實例中獲取它(您在方法內(nèi)部有它):IntentContextViewonItemClicked


Context context = view.getContext();

現(xiàn)在要創(chuàng)建并開始,您可以編寫如下代碼:Intent


Intent intent = new Intent(context, ActivityYouNeedToStart.class);

context.startActivity(intent);

因此,最終代碼是:


@Override

public void onItemClicked(View view, int position) {

    Context context = view.getContext();

    Intent intent = new Intent(context, ActivityYouNeedToStart.class);

    context.startActivity(intent);

}


查看完整回答
反對 回復(fù) 2022-09-14
?
白衣非少年

TA貢獻1155條經(jīng)驗 獲得超0個贊

您應(yīng)該將活動/片段提供給 的構(gòu)造函數(shù)。然后你可以使用這個contextadapter

Intent intent = new Intent(context,NewActivity.class);
context.startActivity(intent);


查看完整回答
反對 回復(fù) 2022-09-14
?
慕容森

TA貢獻1853條經(jīng)驗 獲得超18個贊

以下是在回收視圖中實現(xiàn)子項的單擊偵聽器的一種方法。


public class HotelAdapter extends RecyclerView.Adapter {

private List<Top10Hotel> hotels;

private Context context;


private SavedHotelViewModel viewModel;


public HotelAdapter(List<Top10Hotel> hotels, Context context, SavedHotelViewModel viewModel) {

    this.hotels = hotels;

    this.context = context;

    this.viewModel = viewModel;

}


@NonNull

@Override

public MyHotelViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {

    View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.recommended_hotel, viewGroup, false);

    return new MyHotelViewHolder(view);

}


@Override

public void onBindViewHolder(@NonNull MyHotelViewHolder holder, int position) {


    Top10Hotel hotel = hotels.get(position);

    holder.hotelsTextView.setText(hotel.getHotel_name());


    Glide.with(context)

            .load(hotel.getHotel_image_url())

            .error(R.drawable.ic_location_city)

            // read original from cache (if present) otherwise download it and decode it

            .diskCacheStrategy(DiskCacheStrategy.SOURCE)

            .into(holder.hotelsImageView);

    long rating = 0;


    if(hotel.getHotel_rating() != null && hotel.getHotel_rating().length()>0){

        try {

            rating = Long.parseLong(hotel.getHotel_rating());

        }catch (NumberFormatException e){

            rating =1;

        }


    }


    String rate= null;

    if(rating>=4.5){

        rate = String.valueOf(rating)+" Excellent";

    }else if(rating>=4 && (rating < 4.5)){

        rate = String.valueOf(rating)+" Very Good";

    }else {

        rate = String.valueOf(rating)+" Good";

    }

    holder.rating.setText(rate);

    String range = "?"+hotel.getHotel_low_range()+" - "+"?"+hotel.getHotel_high_range();

    holder.priceRange.setText(range);


    holder.area.setText(hotel.getHotel_area());



    holder.saveImage.setOnClickListener(view -> {


        RoomBooking hotelSaved = new RoomBooking(hotel.getHotel_id(),

                hotel.getHotel_name(),

                hotel.getHotel_area(),

                hotel.getHotel_low_range(),

                hotel.getHotel_high_range(),

                hotel.getHotel_rating(),

                hotel.getHotel_image_url());


        if(hotel.isSaved()){

            holder.saveImage.setImageResource(R.drawable.ic_favorite_black);

            hotel.setSaved(false);

            viewModel.delete(hotelSaved);

            Toast.makeText(context, "Removed", Toast.LENGTH_SHORT).show();

        }else {

            holder.saveImage.setImageResource(R.drawable.ic_saved_love);

            hotel.setSaved(true);


            viewModel.insert(hotelSaved);

            Toast.makeText(context, "saved", Toast.LENGTH_SHORT).show();

        }


        notifyDataSetChanged();

    });


    holder.linearLayout.setOnClickListener(view -> navigateToHotelActivity(hotel.getHotel_id(),hotel.getHotel_name()));

    holder.hotelsImageView.setOnClickListener(view -> navigateToHotelActivity(hotel.getHotel_id(),hotel.getHotel_name()));



}


private void navigateToHotelActivity(String hotelId, String hotelName) {


            Intent intent = new Intent(context, HotelActivity.class);

            intent.putExtra("hotelId",hotelId);

            intent.putExtra("hotelName",hotelName);

            context.startActivity(intent);

}


@Override

public int getItemCount() {

    return hotels.size();

}


public class MyHotelViewHolder extends RecyclerView.ViewHolder {


    TextView hotelsTextView,rating,priceRange,area;

    ImageView hotelsImageView;

    ImageView saveImage;

    LinearLayout linearLayout;


    public MyHotelViewHolder(@NonNull View itemView) {

        super(itemView);


        linearLayout = itemView.findViewById(R.id.linearLayoutH);


        hotelsTextView = itemView.findViewById(R.id.hotels_name);

        hotelsImageView = itemView.findViewById(R.id.hotels_image);

        rating = itemView.findViewById(R.id.hotel_rating);

        priceRange = itemView.findViewById(R.id.price_range);

        area = itemView.findViewById(R.id.area_name);


        saveImage = itemView.findViewById(R.id.save_icon);

    }

}



}


查看完整回答
反對 回復(fù) 2022-09-14
  • 3 回答
  • 0 關(guān)注
  • 105 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號