我想知道如何显示从extends AppCompatActivity
到extends Fragment
的值。第二个是Tabbed活动中的一个Tab,我只能调用extends Fragment
java文件。进入类,我有3个TextViews
包含要打印的值。下面是我的一段代码在指。
public class Tab1Signal extends AppCompatActivity {
TextView tv1,tv2,tv3;
int value=0,dbm=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_tab1);
tv1=(TextView)findViewById(R.id.info);
tv2=(TextView)findViewById(R.id.info2);
tv3=(TextView)findViewById(R.id.info3);
TelephonyManager tm=(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
tm.listen(new Tab1Signal2(this), PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
String opname="\nOperator ID:"+" "+tm.getNetworkOperator();
opname=opname+"\nOperator Name:"+" "+tm.getNetworkOperatorName();
int phoneType=tm.getPhoneType(),networkType=tm.getNetworkType();
String ptype="",ntype="";
switch(phoneType) {
case TelephonyManager.PHONE_TYPE_CDMA:
ptype="\nPhone Type: CDMA\n";
break;
case TelephonyManager.PHONE_TYPE_GSM:
ptype="\nPhone Type: GSM\n";
break;
case TelephonyManager.PHONE_TYPE_SIP:
ptype="\nPhone Type: SIP\n";
break;
case TelephonyManager.PHONE_TYPE_NONE:
ptype="\nPhone Type: NONE\n";
break;
}
tv1.setText(opname+ptype+ntype);
}
第二班
public class Tab1Values extends Fragment{
public Tab1Values() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v=inflater.inflate(R.layout.fragment_tab1, container, false);
return v;
}
}
谢谢