使用此代码,我可以轻松地动态插入一些布局.布局包含一个Button我想要启动的startActivityForResult.现在,当我得到结果(文本)时,我想将其设置为Button.
btnAggiungiCampo.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
PopupMenu popup = new PopupMenu(this, btnAggiungiCampo);
popup.getMenuInflater().inflate(R.menu.menu_campi, popup.getMenu());
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
View child = null;
if (item.getTitle().equals(getString(R.string.Text))) {
child = getLayoutInflater().inflate(R.layout.inflate_campo, null);
rlCampi.addView(child);
Button btnGeneraPSW = (Button) child.findViewById(R.id.imageButton3);
btnGeneraPSW.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent inte = new Intent(this, Genera_password.class);
startActivityForResult(inte, REQ_CODE_ACT1);
}
});
}
}
}
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, …Run Code Online (Sandbox Code Playgroud) android android-button android-activity startactivityforresult
我正试图在一个按钮中显示一系列按钮JScrollpane.阅读时,我设法退出此代码,但没有显示任何内容.我不明白可能的错误.谢谢你的帮助
正如我所做的那样,我做了一些修改,但我编辑了但没有作
编辑 或我是愚蠢的,或者这是一些其他问题.这是我输出图像的完整代码
public class Main extends javax.swing.JFrame {
private final JPanel gridPanel;
public Main() {
initComponents();
// EXISTING PANEL
gridPanel = new JPanel();
JScrollPane scrollPane = new JScrollPane(gridPanel);
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
JPanel borderLayoutPanel = new JPanel(new BorderLayout());
borderLayoutPanel.add(scrollPane, BorderLayout.CENTER);
this.Avvio();
}
private void Avvio() {
JPanel pane = new JPanel(new GridBagLayout());
pane.setBorder(BorderFactory.createLineBorder(Color.BLUE));
pane.setLayout(new GridBagLayout());
for (int i = 0; i < 10; i++) {
JButton button;
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.HORIZONTAL;
c.anchor = GridBagConstraints.PAGE_START;
button …Run Code Online (Sandbox Code Playgroud) 我有一个包含名称和颜色代码的数组.我想用gridview中的颜色为数组中的颜色着色.我创建了这段代码但是我得到了NPE,这是错误:
Logcat输出:
Caused by: java.lang.NullPointerException
10-06 11:03:30.513 25902-25902/? E/AndroidRuntime:
at android.graphics.Color.parseColor(Color.java:211)
Run Code Online (Sandbox Code Playgroud)
颜色XML文件:
<array name="colors">
<item name="White">#FFFFFF</item>
<item name="Ivory">#FFFFF0</item>
<item name="LightYellow">#FFFFE0</item>
<item name="Yellow">#FFFF00</item>
<item name="Snow">#FFFAFA</item>
<item name="FloralWhite">#FFFAF0</item>
</array>
Run Code Online (Sandbox Code Playgroud)
源代码:
public class ColorPickerAdapter extends BaseAdapter {
private Context context;
private List<Integer> colorList = new ArrayList<Integer>();
public ColorPickerAdapter(Context context) {
this.context = context;
String colors[] = context.getResources().getStringArray(R.array.colors);
colorList = new ArrayList<Integer>();
// add the color array to the list
for (int i = 0; i < colors.length; i++) {
colorList.add(Color.parseColor(colors[i]));
}
[..]
Run Code Online (Sandbox Code Playgroud) 我已成功使用此项目在Google云端硬盘中创建或修改文件.现在我需要将文件下载到设备的外部存储器中.我可以读取文件的内容,我可以保存它.但是当我尝试在桌面上打开它时,文件已损坏.
@Override
protected Void doInBackground(Void... params) {
mBusy = true;
ArrayList<ContentValues> cvs = GDAA.searchDB(UT.FILE_NAME);
if (cvs != null) for (ContentValues cv : cvs) {
String gdid = cv.getAsString(UT.GDID);
System.out.println("ID..... " + gdid);
byte[] buf = GDAA.read(gdid);
String str = buf == null ? "" : new String(buf);
File fl = UT.str2File(str, "myfile.db");
}
----------------------------------------------
static File str2File(String str, String name) {
if (str == null) return null;
byte[] buf = str.getBytes();
File fl = new File(Environment.getExternalStorageDirectory(), name);
if …Run Code Online (Sandbox Code Playgroud) 我想将特定的CSV文件导入数据库.我正在使用库aFileChooser来选择文件,但不会导入CSV文件中的数据.我哪里错了?谢谢
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch(requestCode) {
case ACTIVITY_CHOOSE_FILE1: {
if (resultCode == RESULT_OK){
Uri uri = data.getData();
File file1 = com.ipaulpro.afilechooser.utils.FileUtils.getFile(uri);
proImportCSV(file1);
}
}
}
}
ricevi_csv= (Button) findViewById(R.id.but_ricevi_csv);
ricevi_csv.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent chooseFile;
Intent intent;
chooseFile = new Intent(Intent.ACTION_GET_CONTENT);
chooseFile.setType("application/image");
intent = Intent.createChooser(chooseFile, "Choose a CSV");
startActivityForResult(intent, ACTIVITY_CHOOSE_FILE1);
}
});
}
private void proImportCSV(File from){
File root = Environment.getExternalStorageDirectory();
File exportDir = new File(root.getAbsolutePath());
File csvFile …Run Code Online (Sandbox Code Playgroud) 我以支持的格式(yyyy-mm-dd)在sqlite数据库中插入日期.现在我希望用户在查询时根据国家/地区显示日期格式(意大利dd-mm-yyyy,美国yyyy-mm-dd等...)
我如何能?谢谢
我正在使用新的NavigationView,因为我将项目升级到API 23,效果很好,但是如何设置默认片段?打开到应用程序开头的片段.这是我的代码,感谢您的建议.
public class MainActivity extends AppCompatActivity {
private Toolbar toolbar;
private NavigationView navigationView;
private DrawerLayout drawerLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Initializing Toolbar and setting it as the actionbar
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
//Initializing NavigationView
navigationView = (NavigationView) findViewById(R.id.navigation_view);
//Setting Navigation View Item Selected Listener to handle the item click of the navigation menu
navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
// This method will trigger on item Click of navigation menu
@Override
public boolean onNavigationItemSelected(MenuItem menuItem) { …Run Code Online (Sandbox Code Playgroud)