我一直在寻找有关如何始终在ActionBar下方显示ActionBar选项卡的任何信息,即使手机朝向横向也是如此.我知道它会自动将标签放在ActionBar中,具体取决于屏幕上是否有足够的空间来容纳它们,但我希望它们始终固定在ActionBar下面,即使在横向上也是如此.我发现了一个类似的问题没有明确答案:如何在操作栏下方显示标签.我也知道很多谷歌应用程序,如; Google Play,Google Music等实现了这种类型的设计模式,因此它显然是可以实现的,并且可以作为设计模式使用.
我目前正在使用ActionBarSherlock库来创建我的滑动标签导航,如果有人知道如何自己做这件事,我真的很感激.提前致谢.
这是我的活动代码:
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
viewPager = new ViewPager(this);
viewPager.setId(R.id.pager);
setContentView(viewPager);
tabsAdapter = new TabsAdapter(this, viewPager); // Declares the tabs adapter class with the view pager view
actionBarTabs = getSupportActionBar();
actionBarTabs.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
actionBarTabs.setCustomView(spinnerView);
actionBarTabs.setDisplayShowCustomEnabled(true);
/* Adds fragments to the tabs adapter */
tabsAdapter.addTab(actionBarTabs.newTab().setText("FRAG1"), Fragment_1.class, null);
tabsAdapter.addTab(actionBarTabs.newTab().setText("FRAG2"), Fragment_2.class, null);
tabsAdapter.addTab(actionBarTabs.newTab().setText("FRAG3"), Fragment_3.class, null);
}
Run Code Online (Sandbox Code Playgroud)
这是我的TabsAdapter代码:
public class TabsAdapter extends FragmentPagerAdapter implements ActionBar.TabListener , ViewPager.OnPageChangeListener
{
private final Context context;
private final ActionBar actionBar; …Run Code Online (Sandbox Code Playgroud) 我知道您可以使用printf并使用StringBuilder.append(String.format("%x", byte))将值转换为HEX值并在控制台上显示它们.但我希望能够实际格式化字节数组,以便每个字节显示为HEX而不是十进制.
这是我的代码的一部分,我已经说过我说的前两种方式:
if(bytes > 0)
{
byteArray = new byte[bytes]; // Set up array to receive these values.
for(int i=0; i<bytes; i++)
{
byteString = hexSubString(hexString, offSet, CHARSPERBYTE, false); // Isolate digits for a single byte.
Log.d("HEXSTRING", byteString);
if(byteString.length() > 0)
{
byteArray[i] = (byte)Integer.parseInt(byteString, 16); // Parse value into binary data array.
}
else
{
System.out.println("String is empty!");
}
offSet += CHARSPERBYTE; // Set up for next word hex.
}
StringBuilder sb = new …Run Code Online (Sandbox Code Playgroud) 我试图使用类似于C#的方法string.SubString(int start, int length).
但是Java中的substring函数是string.substring(int start, int end).
我希望能够将起始位置和长度传递给子字符串函数.
任何人都可以帮我解决这个问题吗?
我正在尝试使用NFC创建应用程序,我只是想尝试读取NFC标签并从标签中获取文本消息并将其放入TextView.我已经有了代码,但是当我尝试将手机与NFC标签配对时没有任何反应.
这是我的代码,有人可以看看它,看看我做错了什么,需要做些什么来解决问题:
Button measurementsDataButton;
NfcAdapter myNfcAdapter;
PendingIntent myPendingIntent;
IntentFilter ndef;
IntentFilter[] filters;
String[][] techLists;
int mCount;
TextView mText;
String payload;
byte payloadHeader;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_nfc_scanner);
final ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
mText = (TextView) findViewById(R.id.flowTextView1);
measurementsDataButton = (Button) findViewById(R.id.measurementsButton1);
measurementsDataButton.setOnClickListener(this);
myNfcAdapter = NfcAdapter.getDefaultAdapter(this);
myPendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
ndef = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
filters = new IntentFilter[] {ndef, };
techLists = new String[][] {new String[] {Ndef.class.getName()}, new String[] {NdefFormatable.class.getName()}};
}
@Override
public void …Run Code Online (Sandbox Code Playgroud) 我创建了要从按钮单击动态添加到布局的视图,但是当我旋转设备格局时,视图消失.有人可以看看我的代码并解释如何阻止这种情况发生.
这是代码:
public class TestContainerActivity extends Activity implements OnClickListener {
LinearLayout containerLayout;
Button testButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test_container);
testButton = (Button)findViewById(R.id.testContainerButton1);
testButton.setOnClickListener(this);
containerLayout = (LinearLayout)findViewById(R.id.testContainerLayout);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.test_container, menu);
return true;
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(v==testButton){
createNewLayout();
}
}
public void createNewLayout(){
LayoutInflater layoutInflater = (LayoutInflater) getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View …Run Code Online (Sandbox Code Playgroud) 我目前创建了一个使用XmlSerializer从对象创建XML文件的函数.我一直在研究使用不同形式的多线程,以便在GUI仍然可用且仍在更新的同时将文件保存在后台.我看过使用AsyncTask来做这件事,但我不确定实现它的最佳方法是什么.请任何人帮助我,并提前感谢你.
这是我到目前为止的代码:
private String fileName;
private DataObjects dataObjects;
public SetCachedValuesFile()
{
}
public void setFileName(String refFileName)
{
fileName = refFileName;
}
public void setDataObjects(DataObjects refDataObjects)
{
dataObjects = refDataObjects;
}
public String getFileName()
{
return fileName;
}
public DataObjects getDataObjects()
{
return dataObjects;
}
public void updateValues()
{
ArrayList<DataObject> arrayListDataObject = dataObjects.getDataObjects();
try
{
/* Creates a new file and its directory. */
File directory = new File(Environment.getExternalStorageDirectory() + "/XML_FILES/");
directory.mkdirs();
File newFile = new File(directory, fileName + ".xml");
FileOutputStream …Run Code Online (Sandbox Code Playgroud) 我不知道为什么我会得到一个NullPointerException,但它正在线上发生spinner.setAdapter(arrayAdapter).任何人都可以看看我的代码,看看问题是什么以及如何解决它.提前致谢.
这是我的代码:
public class SlidingTabsActivity extends SherlockFragmentActivity
{
ViewPager viewPager;
TabsAdapter tabsAdapter;
ActionBar actionBarTabs;
Spinner spinner;
ArrayAdapter<String> arrayAdapter;
PopupFirmware popupFirmware; // Popup firmware class instance
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
viewPager = new ViewPager(this);
viewPager.setId(R.id.pager);
setContentView(viewPager);
arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, R.array.device_description);
spinner = (Spinner) findViewById(R.id.tabsSpinner);
spinner.setAdapter(arrayAdapter);
actionBarTabs = getSupportActionBar();
actionBarTabs.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
actionBarTabs.setCustomView(spinner);
actionBarTabs.setDisplayShowCustomEnabled(true);
actionBarTabs.setDisplayHomeAsUpEnabled(true);
tabsAdapter = new TabsAdapter(this, viewPager); // Declares the tabs adapter class with the view pager view
popupFirmware = new PopupFirmware(this); // Declaring …Run Code Online (Sandbox Code Playgroud) 我正在创建一个程序,它读取文本文件并拆分单词并将它们存储在列表中.我一直在尝试创建一个函数,它接受一个String,它是文件中的整个文本字符串,并删除标点符号,例如";",",","." 但遗憾的是还没有运气.该程序在没有标点符号功能的情况下工作,但是当我将其包含在内时(toWords fileContents)请不要.请有人看看我做了什么,看看我做错了什么.
这是我到目前为止的代码:
main = do
contents <- readFile "LargeTextFile.txt"
let lowContents = map toLower contents
let outStr = countWords (lowContents)
let finalStr = sortOccurrences (outStr)
let reversedStr = reverse finalStr
putStrLn "Word | Occurrence "
mapM_ (printList) reversedStr
-- Counts all the words.
countWords :: String -> [(String, Int)]
countWords fileContents = countOccurrences (toWords (removePunc fileContents))
-- Splits words and removes linking words.
toWords :: String -> [String]
toWords s = filter (\w -> w `notElem` …Run Code Online (Sandbox Code Playgroud) 我试图在Java中创建一个相当于的方法
'Uri.IsHexDigit(char)'在C#中.我想检查字符是否在一组char数组中,以查看它是否是正确的字符.请任何人都可以查看我的代码,看看我做错了什么.先感谢您.
到目前为止,这是我的代码:
public boolean hexChecker(char c)
{
String string = "0123456789abcdefABCDEF";
char[] charArray = string.toCharArray();
for(char ch : charArray)
{
if(c == ch)
{
System.out.println("It worked!");
return true;
}
else
{
System.out.println("It did not work!");
return false;
}
}
return false;
}
Run Code Online (Sandbox Code Playgroud) 我是C语言编程的新手,我正在使用C编译器为Raspberry Pi编程.我想要做的就是创建一个函数,该函数将String作为参数并将其保存为特定位置的文本文件.我想检查该文件位置以查看存在的文件,并将新文件保存到该文件夹,并以1的增量添加到文件名中.
例如,文件夹包含:
TestFile1 TestFile2
我希望能够创建保存为TestFile3的新文件.
这是我到目前为止的代码,想知道我是否在正确的位置并获得任何提示,请:
void WriteToFile(unsigned char *pID)
{
printf("Writing to file. . . . .\n");
/* Checking to see how many files are in the directory. */
int *count = 0;
DIR *d;
struct dirent *dir;
d = opendir("table_orders");
if(d)
{
while((dir = readdir(d)) != NULL)
{
printf("%s\n", dir->d_name);
count = count + 1; // Adds 1 to count whenever a file is found.
}
closedir(d);
}
char str[sizeOf(count)]; // Creates string.
sprintf(str, "%d", count); // …Run Code Online (Sandbox Code Playgroud)