我想知道getString().我可以看到这样做getString(R.string.some_text)有效.也getResources().getString(R.string.connection_error)有效.所以我的问题是为什么我们应该使用getString或什么时候?谢谢!
有谁可以请帮助发现错误?这是代码:
byte[] oriBytes = { 0xB0, 0x2D }; // oriBytes -> 0xB0, 0x2D
string oriInStr = Encoding.ASCII.GetString(oriBytes); // oriInStr -> "?-"
oriBytes = Encoding.ASCII.GetBytes(oriInStr); // oriBytes -> 0x3F, 0x2D
Run Code Online (Sandbox Code Playgroud)
我无法取回原来的字节值0xB0,0x2D.
我有这个代码:
public void chyt_data()
{
try
{
SqlCommand novyprikaz = new SqlCommand("SELECT * FROM zajezd WHERE akce=" + currentrowstring, spojeni);
spojeni.Open();
SqlDataReader precti = novyprikaz.ExecuteReader();
if (precti.Read())
{
zakce.Text = precti.GetString(0);
zname.Text = precti.GetString(2);
}
}
catch (Exception ex)
{
MessageBox.Show("Chybové hlášení2: " + ex.Message.ToString());
}
spojeni.Close();
}
Run Code Online (Sandbox Code Playgroud)
如果我在其中插入列名称,它是这样的:
zakce.Text = precti.GetString("akce");
Run Code Online (Sandbox Code Playgroud)
它不会起作用.
愿有人请帮我解决这个问题吗?非常感谢
它给出了两个错误:
1:错误1'System.Data.Common.DbDataReader.GetString(int)'的最佳重载方法匹配有一些无效的参数
2:错误2参数1:无法从'string'转换为'int'
我正在测试FragmentPagerAdapter,之前我在一个类中完成了所有这些操作.一切正常,但是一旦我分离了SectionsPagerAdapter类,getString就不能在getPageTitle函数下工作了.
我知道getPageTitle是PagerAdapter类的一部分,但我想知道在这个类中包含该函数的最佳方法是什么.我需要延长课程吗?
SectionsPageAdapter类
import java.util.Locale;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
// A FragmentPagerAdapter that returns a fragment corresponding to one of the sections/tabs/pages.
public class SectionsPagerAdapter extends FragmentPagerAdapter {
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
// getItem is called to instantiate the fragment for the given page.
// Return a DummySectionFragment (defined as a static inner class
// below) with the page number as its lone argument.
Fragment fragment = new …Run Code Online (Sandbox Code Playgroud) 有没有办法以编程方式更改R.string?因为它抛出了一个错误.
基本上我想这样做:
String parkAdd = getString(R.string.stg_ParkAddress_+id);
因为我有根据ID更改的硬编码字符串.
我试图这样做但不起作用:
String parkAdd = getString(R.string.stg_ParkAddress_1);
parkAdd = parkAdd.replace("1",id);
if (!parkAdd.equalsIgnoreCase("")){
tvParkAddress.setText(parkAdd);
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试0s从a 开始获取数值JSONObject.问题是该方法将字符串转换为double.例:
的JSONObject:
{
"LATITUDE1":41,
"LATITUDE2":06962
}
Run Code Online (Sandbox Code Playgroud)
我用的时候
String lat2 = object.getString("LATITUDE2");
Run Code Online (Sandbox Code Playgroud)
字符串lat2显示为6962.0.我怎样才能使字符串显示在json文件中(如06962)?
然后我需要连接两个值并在它们之间添加一个点以获得十进制数,41.06962这就是为什么我需要将值作为字符串获取.
谢谢
我想通过setText()显示粗体文本,但是我只是看到文本不是粗体:(我该如何解决这个问题?
这是我的代码:String.xml:
<string name="country"><b>AMERICA-default</b></string>
Run Code Online (Sandbox Code Playgroud)
我的Java代码:
Resources resources;
TextView tvCountry;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
Log.d("test","onCreate()-second Activity");
setContentView(R.layout.activity_second);
resources = getResources();
tvCountry = (TextView) findViewById(R.id.tvCountry);
tvCountry.setText(resources.getString(R.string.country));//its not working !Text is not bold!
//CANNOT USE : tvCountry.setText(R.string.country);
}
Run Code Online (Sandbox Code Playgroud)