我被卡住了:(
在我的应用程序中,每当它获得新位置的更新时我都需要从CLLocationManager更新.我没有使用XIB/NIB文件,我编写的所有内容都是以编程方式完成的.代码:
.h
@interface TestViewController : UIViewController
UILabel* theLabel;
@property (nonatomic, copy) UILabel* theLabel;
@end
Run Code Online (Sandbox Code Playgroud)
.m
...
-(void)loadView{
....
UILabel* theLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0,0.0,320.0,20.0)];
theLabel.text = @"this is some text";
[self.view addSubView:theLabel];
[theLabel release]; // even if this gets moved to the dealloc method, it changes nothing...
}
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
NSLog(@"Location: %@", [newLocation description]);
// THIS DOES NOTHING TO CHANGE TEXT FOR ME... HELP??
[self.view.theLabel setText:[NSString stringWithFormat: @"Your Location is: %@", [newLocation description]]]; …Run Code Online (Sandbox Code Playgroud) 我在字符串资源中设置TextView中的文本.通常,希伯来语以从右到左的格式运作.当我设置文本时,它在LG,三星,索尼手机中设置文本从右到左格式,但在HTC中它不起作用.它在HTC中以从左到右的格式工作.甚至我将Gravity设置为Java文件中的TextView.
TextView中的文本应根据屏幕大小进行调整.例如,如果它是320 x 480,那么它显示为4行,但如果它是Galaxy Tab,那么可能有2行.
这是我的代码段:
在Java中:
private TextView mVersionInfo, mVersionDescriptionOne, mVersionDescriptionTwo, mVersionDescriptionThree;
mVersionInfo = (TextView)findViewById(R.id.VersionInfo);
mVersionDescriptionOne = (TextView)findViewById(R.id.VersionDesc1);
mVersionDescriptionTwo = (TextView)findViewById(R.id.VersionDesc2);
mVersionDescriptionThree = (TextView)findViewById(R.id.VersionDesc3);
mVersionDescriptionOne.setGravity(Gravity.RIGHT);
mVersionDescriptionTwo.setGravity(Gravity.RIGHT);
mVersionDescriptionThree.setGravity(Gravity.RIGHT);
Run Code Online (Sandbox Code Playgroud)
在XML中:
<TextView android:id="@+id/VersionDesc1"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="@string/versiondesc1" android:textColor="#000000"
android:layout_marginTop="5dip" android:gravity="right"
android:layout_alignParentRight="true" android:layout_marginRight="10dip"
android:layout_below="@+id/Share" android:textSize="13sp"
android:layout_alignRight="@+id/Body" />
<TextView android:id="@+id/VersionDesc2"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="@string/versiondesc2" android:textColor="#000000"
android:layout_alignParentRight="true" android:layout_marginRight="10dip"
android:layout_below="@+id/VersionDesc1" android:textSize="13sp"
android:layout_marginTop="5dip" android:gravity="right"
android:layout_alignRight="@+id/Body" />
<TextView android:id="@+id/VersionDesc3"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="@string/versiondesc3" android:textColor="#000000"
android:layout_alignParentRight="true" android:layout_marginRight="10dip"
android:layout_below="@+id/VersionDesc2" android:textSize="13sp"
android:layout_marginTop="5dip" android:gravity="right"
android:layout_alignRight="@+id/Body" />
Run Code Online (Sandbox Code Playgroud)
在字符串资源中:
<string name="versiondesc1">????????? ?????? ???? ???? ??????? ??? ????? …Run Code Online (Sandbox Code Playgroud) 我有一个包含三个项目的微调器,我使用XML字符串数组资源来提供它.当您打开活动时,微调器通常会显示数组列表中的第一个项目.我想更改它并在选择项目之前在微调器中显示"选择一个"文本.
我怎样才能做到这一点?
我在使用格式和多个值的文本视图中设置文本时遇到问题.
holder.car.setText(R.string.mycar + lm.getCarName() + R.string.year + lm.getYear());
Run Code Online (Sandbox Code Playgroud)
这给了我"2143545 Camero 2143213 1977"
我从网上尝试了很少的其他"解决方案"
holder.car.setText(getString(R.string.mycar) + lm.getCarName() + getString(R.string.year) + lm.getYear()); << not work, getString undefine>>
Run Code Online (Sandbox Code Playgroud)
我甚至尝试过String.valueOf(R.string.mycar); getResources().getText(R.String.mycar),但它仍无法正常工作.
如果有人可以帮助我,那将是很好的,谢谢
我尝试显示文本和图像,Html.fromHtml()但它在图像显示中不起作用.
message = (TextView) findViewById (R.id.message);
message.setText(Html.fromHtml(
"<p><b>First, </b><br/>" +
"Please press the" + "<img src = 'addbutton.png' />" + " to insert a new event.</p>"));
Run Code Online (Sandbox Code Playgroud)
文本显示良好但图像无法显示.怎么能改善呢?
我试图nameField在点击Label被叫label1后使输入出现在Button被叫button1中.现在它说:'txt',我理解为什么.但我不知道如何使用字符串!谁能解释一下我做错了什么以及如何正确使用这个字符串?
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class thisismytest2 {
public static void main(String[] args) {
final JFrame frame = new JFrame();
JPanel panel = new JPanel();
JTextField nameField = new JTextField("...", 2);
JButton button1 = new JButton();
final JLabel label1 = new JLabel();
label1.setText("txt");
label1.setVisible(false);
String txt = nameField.getText();
frame.add(panel);
panel.add(button1);
panel.add(label1);
frame.setSize(200,200);
frame.setVisible(true);
panel.add(nameField);
frame.setSize(600,400);
nameField.setBounds(400, 40, …Run Code Online (Sandbox Code Playgroud) 这是我的ListActivity ,单击列表后,它将启动一个新列表activity,其中显示每个景点的完整详细信息。我不知道如何实现完整的详细信息页面。你们能给我展示一些从以前的数据中检索数据的完整详细活动的代码吗list?
公共类 AttractionsListActivity 扩展 ListActivity {
私有静态MyDB mDbHelper;
String[] from = new String[] { Constants.TITLE_NAME , Constants.ADDRESS_NAME };
int[] to = new int[] {R.id.place_title, R.id.place_address};
私有游标c;
@覆盖
公共无效onCreate(捆绑保存实例状态){
super.onCreate(savedInstanceState);
mDbHelper = new MyDB(this);
mDbHelper.open();
c = mDbHelper.getplaces();
setListAdapter(新的SimpleCursorAdapter(这个,
R.layout.list_place,c,
从到));
最终ListView lv = getListView();
lv.setOnItemClickListener(new OnItemClickListener() {
公共无效onItemClick(AdapterView父级,视图视图,int位置,长id){
Intent newActivity = new Intent(view.getContext(), Place.class);
启动活动(新活动);
}
});
}
}
我不知道如何实现此活动来处理 AttractionslistActivity.Class 中的操作
公共类地点扩展活动{
私有静态最终字符串CLASSTAG = Place.class.getSimpleName();
私有 TextView 标题;
私有 TextView 详细信息;
私有 TextView … android view settext simplecursoradapter android-cursoradapter
我有一个问题,这是我用Android开发近三年来从未有过的问题...
我想拍照,拍完照片后,EditText活动的s变得清晰.我在做什么设置的值EditText,以Strings使用getText().toString()拍照后恢复它们.
字符串与数据完美地存储在一起,但是当我使用时setText,它不起作用......奇怪的是它setHint有效!
怎么会这样?
这是我正在使用的代码:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) {
if (resultCode == RESULT_OK) {
// Image captured and saved to fileUri specified in the Intent
grabImage(imgView);
for (int u = 0; u <= 2; u++)
{
if (savedImgs[u].equals(""))
{
imgs = u + 1;
savedImgs[u] = photo.toString();
break;
}
}
/*Bitmap thumbnail = (Bitmap) data.getExtras().get("data"); ---> It …Run Code Online (Sandbox Code Playgroud) 我是android开发的新手,我想要setText一个数字,我正面临这个问题,并尝试了所有可能的方法来解决它.
请提供解决此问题的代码
代码如下:
public class GameActivity extends Activity implements View.OnClickListener{
int correctAnswer;
Button buttonObjectChoice1;
Button buttonObjectChoice2;
Button buttonObjectChoice3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//here we initialize all our varibles
int partA = 9;
int partB = 2;
correctAnswer = partA * partB;
int wrongAnswer1 = correctAnswer - 1;
int wrongAnswer2 = correctAnswer + 1;
TextView textObjectPartA = (TextView)findViewById(R.id.textPartA);
TextView textObjectPartB = (TextView)findViewById(R.id.textPartB);
buttonObjectChoice1 = (Button)findViewById(R.id.buttonChoice1);
buttonObjectChoice2 = (Button)findViewById(R.id.buttonChoice2);
buttonObjectChoice3 = (Button)findViewById(R.id.buttonChoice3);
textObjectPartA.setText("" + partA);
textObjectPartB.setText("" …Run Code Online (Sandbox Code Playgroud) 我尝试了以下代码来连接“数字”(整数变量)和“$”(字符串),但我收到了来自 android studio 的警告:“不要连接用 setText 显示的文本。使用带有占位符的资源字符串。” 并建议我添加“ @SuppressLint("SetTextI18n")”。在此之后,警告消失了。
连接字符串有什么问题。为什么我们需要添加
@SuppressLint("SetTextI18n")
fun displayPrice(number: Int){
price_text_view.text= "$number$"
}
Run Code Online (Sandbox Code Playgroud)