【发布时间】:2018-10-10 14:44:48
【问题描述】:
我正在使用自定义 TextView,但我对此感到非常沮丧。 Idk如何完成代码....我的代码是:
public class TestTextView extends TextView{
static BluetoothSocket mSocket;
Context c;
public TestTextView(Context mContext){
super(mContext);
mBTConnected(c);
}
public static boolean mBTConnected(Context c){
String mOutputName;
Method m;
try{
BluetoothDevice mDevice=BluetoothAdapter.getDefaultAdapter().getRemoteDevice("MAC_ADRS");
m=mDevice.getClass().getMethod("createRfcommSocket", new Class[]{int.class});
mSocket=(BluetoothSocket)m.invoke(mDevice, Integer.valueOf(1));
mSocket.connect();
mOutputName=mDevice.getName().toString();
Log.i("Bluetooth device "+mOutputName," is connected");
return true;
}catch(Exception e){
}return false;
}}
问题:如何将字符串“名称”设置为 Text 到自定义 TextView 以在我的 Xml 布局文件中调用它?
日志:
10-10 17:34:14.900 E/SDAgentPackageStateReceiver(3797): Not going to handle 'com.mort015.BluetoothTextView'! 10-10 17:34:15.055 E/SDAgentPackageStateReceiver(3797): Not going to handle 'com.mort015.BluetoothTextView'! 10-10 17:34:18.610 E/SPPClientService(9467): [PackageInfoChangeReceiver] [handlePkgRemovedEvent] PackageName : com.mort015.BluetoothTextView, true, false 10-10 17:34:24.237 E/AndroidRuntime(30755): Process: com.mort015.BluetoothTextView, PID: 30755 10-10 17:34:24.237 E/AndroidRuntime(30755): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mort015.BluetoothTextView/com.mort015.BluetoothTextView.MainActivity}: android.view.InflateException: Binary XML file line #7: Binary XML file line #7: Error inflating class com.mort015.BluetoothTextView.TestTextView 10-10 17:34:24.237 E/AndroidRuntime(30755): Caused by: android.view.InflateException: Binary XML file line #7: Binary XML file line #7: Error inflating class com.mort015.BluetoothTextView.TestTextView 10-10 17:34:24.237 E/AndroidRuntime(30755): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class com.mort015.BluetoothTextView.TestTextView 10-10 17:34:24.237 E/AndroidRuntime(30755): at com.mort015.BluetoothTextView.MainActivity.onCreate(MainActivity.java:17) 10-10 17:34:24.562 E/cm_cmc_c(5288): app launch:com.mort015.BluetoothTextView
【问题讨论】: