編輯:關於Android編程
需求:我們要點擊進入一家店鋪,根據不同的店鋪,顯示不同條數的子條目 如:消毒間,洗菜間等。。。這些都是或多或少的,所以需要動態添加:
首先自定義View(linearLayout):
package cn.qust.fang.widget; import io.vov.vitamio.MediaPlayer; import io.vov.vitamio.widget.MediaController; import io.vov.vitamio.widget.VideoView; import android.app.Activity; import android.content.ContentResolver; import android.content.ContentValues; import android.content.Context; import android.net.Uri; import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; import android.widget.EditText; import android.widget.LinearLayout; import android.widget.TextView; import android.widget.Toast; import cn.qust.fang.CHANGLIANG.ChangLiang; import cn.qust.fang.DB.DBManager; import cn.qust.fang.domain.Shop; import cn.qust.fang.main.MvplayActivity123; import cn.qust.fang.main.R; public class RightTopChildsLayouts extends LinearLayout { Shop shop=null; private TextView text_name_sub,textview_mvurl; View view; MvplayActivity123 currentactivity; /** * 配菜間 消毒間什麼的 */ String zi_name; /**\ * 配菜間 消毒間的 的視頻url */ String zi_mvurl; public RightTopChildsLayouts(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // TODO Auto-generated constructor stub } //自定義構造函數 public RightTopChildsLayouts(MvplayActivity123 context,Shop shop,String zi_name,String zi_mvurl){ super(context ); view = LayoutInflater.from(context).inflate(R.layout.sub_right_top, null); text_name_sub=(TextView) view.findViewById(R.id.textview1); /** * 存mv_url */ textview_mvurl=(TextView) view.findViewById(R.id.textview_gone); //把獲得的view加載到這個控件中 addView(view); this.currentactivity=context; this.shop=shop; this.zi_mvurl=zi_mvurl; this.zi_name=zi_name; text_name_sub.setText(zi_name); textview_mvurl.setText(zi_mvurl); view.setOnClickListener(new OnClickListener(){ //點擊事件 @Override public void onClick(View v) { // TODO Auto-generated method stub if(!getZi_mvurl().equals("collect")){ //若不是收藏 就切換視頻 System.out.println("點擊=====RightTopChildsLayouts==zi_name========"+getZi_name()); VideoView mVideoView = currentactivity.getmVideoView(); mVideoView.pause(); Uri uri = Uri.parse(getZi_mvurl()); mVideoView.setVideoURI(uri); mVideoView.start(); } else { /** * 在這裡進行收藏 如果已收藏 顯示已收藏 */ System.out.println("點擊=收藏====RightTopChildsLayouts==zi_name========"+getZi_name()); if (getShop() == null) Toast.makeText(getContext(), "收藏失敗", Toast.LENGTH_SHORT).show(); if (!(new DBManager(getContext()).exits(getShop().getShop_id()))) { save2db(getShop()); } else { //Toast.makeText(context, "已收藏", Toast.LENGTH_SHORT).show(); text_name_sub.setText(R.string.haven_collected); } } } }); } private void save2db(Shop shop) { ContentResolver resolver = getContext().getContentResolver(); ContentValues values = new ContentValues(); // System.out.println("baocun11前--------"); values.put("shop_name", shop.getShopname()); values.put("address", shop.getAddress()); values.put("mv_url", shop.getMv_url()); values.put("logo_url", shop.getLogo_url()); values.put("msg", shop.getMsg()); values.put("shop_id", shop.getShop_id()); values.put("shop_phone", shop.getShop_phone()); Uri url = Uri .parse("content://fang.ContentProvider.MyContentProvider_media/" + ChangLiang.TABLE); resolver.insert(url, values); // System.out.println("baocun11成功-----------"); // Toast.makeText(getContext(), "收藏成功", Toast.LENGTH_SHORT).show(); } public Shop getShop() { return shop; } public void setShop(Shop shop) { this.shop = shop; } public String getZi_name() { return zi_name; } public void setZi_name(String zi_name) { this.zi_name = zi_name; } public String getZi_mvurl() { return zi_mvurl; } public void setZi_mvurl(String zi_mvurl) { this.zi_mvurl = zi_mvurl; } //這個可能不太合適 @Override public void setOnClickListener(OnClickListener l) { // TODO Auto-generated method stub super.setOnClickListener(l); // this.currentactivity.finish(); VideoView mVideoView = currentactivity.getmVideoView(); mVideoView.pause(); Uri uri = Uri.parse(zi_name); mVideoView.setVideoURI(uri); mVideoView.start(); mVideoView .setOnPreparedListener(new MediaPlayer.OnPreparedListener() { @Override public void onPrepared(MediaPlayer mediaPlayer) { // optional need Vitamio 4.0 mediaPlayer.setPlaybackSpeed(1.0f); } }); } }上面用到的sub_right_top.xml如下:
下面是動態添加的代碼:在他們的父布局一加載的時候開始動態添加:public class MainTopRightDialog extends Activity { // private MyDialog dialog; private LinearLayout layout; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main_top_right_dialog); // dialog=new MyDialog(this); layout = (LinearLayout) findViewById(R.id.main_dialog_layout); Shop shop1 = (Shop) getIntent().getSerializableExtra("shop_inmvplayer"); MvplayActivity123 mvplayActivity123 = MvplayActivity123.getinstance(); List這個的布局文件(main_dialog_layout)如下:
1.WallpaperManager的基本用法相關方法 設置壁紙的相關方法: - setBitmap(Bitmap bitmap):將壁紙設置為b
通過這片文章可以回答以下兩個問題1、為啥EventBus的事件處理方法必須申明為Public?但是我用protected也是OK的2、粘性事件的原理,為啥發送多次Even
今天咱們看看android studio的jar打包,但是jar包裡面呢res文件是用不了的,那想用圖片文件怎麼辦呢,這裡可以把圖片文件放進assets文件裡面打進jar
android手機怎麼修改hosts。相信很多android手機用戶都會碰到過Google賬號無法登陸的問題。而無法登入安卓市場的情況。我們電腦可以修改電腦