C++中extern "C"的用法。本站提示廣大學習愛好者:(C++中extern "C"的用法)文章只能為提供參考,不一定能成為您想要的結果。以下是C++中extern "C"的用法正文
Android組件之間的通訊有多種完成方法,Broadcast就是個中一種。在activity和fragment之間的通訊,broadcast用的更多本文以一個activity為例。
後果如圖:
結構文件:
<LinearLayout 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:orientation="vertical" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" /> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/textView1" android:layout_marginLeft="27dp" android:layout_marginTop="26dp" android:text="發送播送" /> </LinearLayout>
MainActivity.java
public class MainActivity extends Activity { private Button btn; private TextView tv; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tv = (TextView) this.findViewById(R.id.textView1); //吸收播送 LocalBroadcastManager broadcastManager = LocalBroadcastManager .getInstance(MainActivity.this); IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction("com.example.test1"); BroadcastReceiver mItemViewListClickReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { tv.setText("1111"); } }; broadcastManager.registerReceiver(mItemViewListClickReceiver, intentFilter); btn = (Button) this.findViewById(R.id.button1); btn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { //發送播送 Intent intent = new Intent("com.example.test1"); LocalBroadcastManager.getInstance(MainActivity.this) .sendBroadcast(intent); } }); } }
原文鏈接:http://blog.csdn.net/u012702547/article/details/46816331
以上就是本文的全體內容,願望對年夜家的進修有所贊助,也願望年夜家多多支撐。