我正在开发一个Android应用程序,我在其中制作了一个ListView.我必须在ListView中为每一行添加2个按钮.这两个按钮是添加和删除.当用户选择其中一个按钮时,应采取一些操作.我该怎么做?
我有一个ListView,它通过一个数组向我显示一些数据(在另一个类中,我通过它的对象访问它).
每当我通过上下文菜单从ListView中删除元素时,列表不会刷新,但元素将从数组中删除.如何刷新列表以显示此信息?
码:
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
if (v.getId()==R.id.mainListView) {
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo)menuInfo;
post=info.position;
menu.setHeaderTitle(stocks[info.position]);
String[] menuItems = stt;
for (int i = 0; i<menuItems.length; i++) {
menu.add(Menu.NONE, i, i, menuItems[i]);
}
}
}
@Override
public boolean onContextItemSelected(MenuItem item) {
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo)item.getMenuInfo();
int menuItemIndex = item.getItemId();
String[] menuItems = stt;
String menuItemName = menuItems[menuItemIndex];
listItemName = stocks[info.position];
stockname.remove(post-1);
return true;
}
Run Code Online (Sandbox Code Playgroud)
<!-- Active tab -->
<item android:state_selected="true" android:state_focused="false"
android:state_pressed="false" android:drawable="@drawable/tab_bg_selected" />
<!-- Inactive tab -->
<item android:state_selected="false" android:state_focused="false"
android:state_pressed="false" android:drawable="@drawable/tab_bg_unselected" />
<!-- Pressed tab -->
<item android:state_pressed="true" android:drawable="@color/transparent" />
<!-- Selected tab (using d-pad) -->
<item android:state_focused="true" android:state_selected="true"
android:state_pressed="false" android:drawable="@color/transparent" />
Run Code Online (Sandbox Code Playgroud)
有没有办法在这种选择器中得到错误我想使用这种选择器,但我得到一个错误android:drawable="@color/transparent
我得到这个错误,当我运行它
我没有想法让它发挥作用
我已经AutoCompleteTextView
在我的应用程序中实现了搜索字段。
我想突出显示在AutoCompleteTextView
(搜索文本字段)中输入的文本,以在下拉列表中突出显示。我怎样才能做到这一点?。
我正在开发一个应用程序,首先我们必须搜索和连接可用的配对蓝牙设备.我做到了连接.但之后我放了一个屏幕要求在文本和文件传输之间进行选择.当我选择文本时,将打开另一个屏幕,其中有edittext和按钮.无论用户在edittext中输入什么,点击按钮,都应该转移到BT聊天应用程序等连接的BT设备.我已经通过BT聊天应用程序,但理解起来很复杂.我想要一个单独的功能,它可以完成任务.以下是我的连接代码.
Main.java
public class Main extends Activity implements Runnable
{
protected static final String TAG = "TAG";
private static final int REQUEST_CONNECT_DEVICE = 1;
private static final int REQUEST_ENABLE_BT = 2;
Button mScan;
BluetoothAdapter mBluetoothAdapter;
private UUID applicationUUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
private ProgressDialog mBluetoothConnectProgressDialog;
private BluetoothSocket mBluetoothSocket;
BluetoothDevice mBluetoothDevice;
@Override
public void onCreate(Bundle mSavedInstanceState)
{
super.onCreate(mSavedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
mScan = (Button) findViewById(R.id.Scan);
mScan.setOnClickListener(new View.OnClickListener()
{
public void onClick(View mView)
{
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (mBluetoothAdapter == null)
{
Toast.makeText(Main.this, …
Run Code Online (Sandbox Code Playgroud) 我想在SD卡上创建一个文件.在这里我可以创建文件并将其读/写到应用程序,但我想要的是,文件应该保存在SD卡的特定文件夹中.我该怎么做FileOutputStream
呢?
// create file
public void createfile(String name)
{
try
{
new FileOutputStream(filename, true).close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
// write to file
public void appendToFile(String dataAppend, String nameOfFile) throws IOException
{
fosAppend = openFileOutput(nameOfFile, Context.MODE_APPEND);
fosAppend.write(dataAppend.getBytes());
fosAppend.write(System.getProperty("line.separator").getBytes());
fosAppend.flush();
fosAppend.close();
}
Run Code Online (Sandbox Code Playgroud) 我有一个附加到主活动的Dialog片段,有没有办法我们可以通过按钮Click从DialogFragment启动另一个Activity.
我的Intent调用DialogFragment:
Intent i= new Intent(getActivity(),SecondActivity.class);
startActivity(i);
Run Code Online (Sandbox Code Playgroud)
已注册第二项活动
如下
<activity android:name=".SecondActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.Dialog">
<intent-filter>
<action android:name="com.example.testjsoncall.SecondActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud) 我正在开发一个应用程序,我在其中以字符串格式向服务器发送数据.以下是我的代码.它工作正常.但现在我的问题是如何将整个.txt文件和.doc文件发送到服务器.在我的GUI中,我必须提供用户选择的路径.意味着用户必须选择他/她想要发送的文件的路径...请帮我解决我的问题...谢谢......
activity_main.xml文件
<RelativeLayout 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"
tools:context=".MainActivity" >
<EditText
android:id="@+id/editText1"
android:layout_width="170sp"
android:layout_height="40sp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="16dp"
android:ems="10"
android:hint="@string/ip" />
<EditText
android:id="@+id/editText2"
android:layout_width="100sp"
android:layout_height="40sp"
android:layout_alignBaseline="@+id/editText1"
android:layout_alignBottom="@+id/editText1"
android:layout_marginLeft="24dp"
android:layout_toRightOf="@+id/editText1"
android:ems="10"
android:hint="@string/port"
android:inputType="number" >
<requestFocus />
</EditText>
<EditText
android:id="@+id/editText3"
android:layout_width="300sp"
android:layout_height="200sp"
android:layout_below="@+id/editText1"
android:layout_centerHorizontal="true"
android:layout_marginTop="38dp"
android:ems="10"
android:hint="@string/msg" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="64dp"
android:text="@string/send" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
.java文件
import java.io.IOException;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;
import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends Activity …
Run Code Online (Sandbox Code Playgroud) 我想验证任何给定格式的日期格式。例如在法语中:14-déc-2017
。在正常的英语语言14-Dec-2017
是在%d-%b-%Y
格式。我想要的是任何语言格式的日期都应该得到验证。
在python中,datetime
我使用下面的函数来验证英文日期格式。
datetime.strptime('14-Dec-2017', '%d-%b-%Y')
Run Code Online (Sandbox Code Playgroud)
要验证任何其他语言的日期格式,使用哪个库/函数?
我必须删除元素ArrayList
,但我没有经历过.我必须删除的元素也可用ArrayList
.简而言之,我必须从另一个数组列表中删除一个数组列表.例如假设
ArrayList<String> arr1= new ArrayList<String>();
ArrayList<String> arr2 = new ArrayList<String>();
arr1.add("1");
arr1.add("2");
arr1.add("3");
arr2.add("2");
arr2.add("4");
Run Code Online (Sandbox Code Playgroud)
现在,我必须从arr1中删除arr2中的元素.那么,我的最终答案是1和3.需要做什么?
我创建了用户定义的Map ie
Map<String, Object[]> pass = new TreeMap<String, Object[]>();
Run Code Online (Sandbox Code Playgroud)
我在这里为循环添加数据,如下所示.
int row = 0;
row++;
pass.put(row + "", new Object[] {"Data 1 : ","A"});
row++;
pass.put(row + "", new Object[] {"Data 2:", "B"});
row++;
pass.put(row + "", new Object[] {"Data 3:", "C"});
row++;
pass.put(row + "", new Object[] {"Data 4:", "D"});
Run Code Online (Sandbox Code Playgroud)
但是这些数据与添加的订单不同.Map以随机顺序存储这些数据.但我希望这些数据有序.需要做什么?