我对 android/java 还很陌生。
我在 windows CE
上使用 C#
实现了该函数的完整功能,因此它在 C#
中的作用是将文本放入 TextBox
当用户使用条形码阅读器扫描卡号
时;然后,例如,在 TextBox
中拍摄了 3 张带有文本 KD55
的图片,然后将图片保存为如下名称:
1.0D55
2.1D55
3.2D55 and so on
然后他拿了一个新的Y61然后它就会像这样
1.0Y61
2.1Y61
3.2Y61 and so on
我希望任何人都可以帮助我解决这个问题或将其翻译成 Java/Android
btn_take_photo.setOnClickListener(new FloatingActionButton.OnClickListener() {
@Override
public void onClick(View view) {
cameraimage();
}
});
jpegCallback = new Camera.PictureCallback() {
@Override
public void onPictureTaken(byte[] bytes, Camera camera) {
FileOutputStream outputStream = null;
return;
}
String text = cardnumberbox.getText().toString().trim();
for(int i = 0; i < 100; i++)
{
if(text.substring(0,1).equals("K"))
{
text = (i+1) + "." + i + text.substring(1);
}
else
{
text=(i+1) + "." + i + text ;//.substring(0));
}
}
String photofile = text + ".jpg";
String file_name = file_image.getAbsolutePath() + "/" + photofile;
File picfile = new File(file_name);
try {
outputStream = new FileOutputStream(picfile);
outputStream.write(bytes);
outputStream.close();
} catch (FileNotFoundException e) {
} catch (IOException ex) {
} finally {
}
refreshcamera();
refreshgallery(picfile);
private void refreshgallery(File file) {
Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
intent.setData(Uri.fromFile(file));
sendBroadcast(intent);
}
我是如何用 C# 实现的
string str1 = this.textBoxCardNumber.Text.Substring(0, 1) == "K" ? this.textBoxCardNumber.Text.Substring(1) : this.textBoxCardNumber.Text;
string str2 = (string) (object) Directory.GetFiles(this.picturesPath, "*" + str1 + ".JPG").Length + (object) str1;
this.takenPictures.Add(this.picturesPath + str2 + ".JPG");
this.Cam.SnapshotFile.Filename = str2;
最佳答案
试试这个方法。我假设有 3 张图片(根据你的问题)。所以我把 3 放入 for 循环
import java.io.*;
class StackOvr
{
public static void main(String jsk[])
{
String str = "KD55";
for(int i = 0; i < 3; i++)
{
if(str.substring(0,1).equals("K"))
{
System.out.println( (i+1) + "." + i + str.substring(1));
}
else
{
System.out.println( (i+1) + "." + i + str);//.substring(0));
}
}
}
}
这是我自己测试的代码。
Output
1.0D55
2.1D55
3.2D55
这可能对你有帮助。
关于java - 如何将编辑文本中的第一个字母替换为自动编号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38255406/